开发者

AJAX replace content in DIV not by ID or class

开发者 https://www.devze.com 2023-03-25 06:12 出处:网络
Can some one help me.. I have a script who generates code like this >> <div id=\"imageok\">img1.png</div>

Can some one help me.. I have a script who generates code like this >>

<div id="imageok">img1.png</div>
<div id=开发者_高级运维"imageok">img22.jpg</div>
<div id="imageok">img333.gif</div>

In AJAX the name of the image is called imgname its equal to content of the div.

I want to replace the text inside the div but I can't use the id because its the same for each div.. I tried to search for div by it content (I have the name of the image in the AJAX)

Perhaps its something like.. GET element where content =="img1.png" > replace I just can't write it correct..

Please help me .


I think what you are trying to do can be accomplished more 'neatly' with jQuery.

Have you used jQuery before? If yes, then you can do something like this:

// get content into a variable called 'result'
$('div').each(function(i) {
  if ($(this).text() == 'img1.png') {
    $(this).text(result);
  }
});

I haven't tested this code. Hope it helps.

0

精彩评论

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