1

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!

4 Answers 4

1

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();
Sign up to request clarification or add additional context in comments.

Comments

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

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

1 Comment

This works, but to clear things up, I have 20+ DIV's with the .caption class. I only want to target the DIV that has "[ProductDetail_Espot]" as it's content.
0

Some simple jQuery to get you going...

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

will show it,

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

will replace contents.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.