开发者

jQuery update DOM to access injected html tags

开发者 https://www.devze.com 2023-01-22 16:23 出处:网络
Ok I\'m submitting a form via ajax. The result string is a bunch of html links and images which I append to the body of the DOM.

Ok I'm submitting a form via ajax. The result string is a bunch of html links and images which I append to the body of the DOM. Is it possible to search with jQuery within this new code?

before ajax request:

<div id="results"></div>

after ajax request:

<div id=results"> 
  <img src="somevalidpicture.jpg" class="image"/>
  <img src="somevalidpicture2.jpg" class="image"/>
</div>

How can I run my jQuery code to manipulate that code again? For example:

$(".image").show(slow);

I suspect I cannot access the .image class, because it wasn't there when the page first loa开发者_运维知识库ded. And it doesn't show up in the sourcecode (browser). Is there a way to refresh/update the DOM?


You can access them, as soon as the elements are added to the DOM $(".image") will find them. However slow needs to be in quotes for your particular example:

$(".image").show("slow");

"show" is a key that means 600ms, $(".image").show(600); would have the same effect.


Don't use "View Source" to see what's currently in your page (since it'll show what was there when the page loaded), instead use a DOM inspector like Firebug or the Chrome Developer tools.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号