Jake
Jake

Reputation: 13

Find & Replace Specific DIV With jQuery

I have a page I am working with that has several hidden DIVs that are identically formatted, but the content within each DIV varies. I want to be able to seek out a specific DIV (based on it's content), unhide it, and replace it with custom content.

For instance, I have:

<div class="caption" style="display:none">[ProductDetail_Espot]</div>

And I want:

<div class="caption" style=""><p>My Custom Content</p></div>

I have looked at a couple regex scripts and stuff, but I'm not a genius when it comes to scripting, so any help would be appreciated!

Upvotes: 1

Views: 152

Answers (4)

genesis
genesis

Reputation: 50966

$(function(){
    $(".caption:contains('Espot')).show().html('<p>My custom content</p>');
});

demo: http://jsfiddle.net/EsPym/1/

Upvotes: 1

Felix Kling
Felix Kling

Reputation: 816334

If you know that only one div has this content, then you can use the :contains [docs] selector:

$('.caption:contains("[ProductDetail_Espot]")')
   .html("<p>My Custom Content</p>")
   .show();

Upvotes: 1

Hamid
Hamid

Reputation: 1760

$("#[ELEMENT ID]").click(function(){
$(".caption").show().html('[YOU NEW ACCONT]');
})

Upvotes: 0

Brian
Brian

Reputation: 8616

Some simple jQuery to get you going...

$("#caption").show();

will show it,

$("#caption").html("<p>some html</p>");

will replace contents.

Upvotes: 0

Related Questions