简体   繁体   中英

How to target a div with a class and an inner p tag

I have a structure that looks like this..

<div class="infobubble">
    <a href="#" class="btn-closebubble"></a>
    <p>
PLACE CONTENT HERE
</p>
</div>

How do I use jquery to target the in

tags?

I tried this but did not work.

$("infobubble p").html('My Text');

Your code is wrong, you need to specify that you are looking for a class, like so

$(".infobubble p").html('My Text');

Your code $("infobubble p") would be looking for a tag element named infobubble which does not exist

$(".infobubble p").html('My Text');

in jQuery you need to add an '.' to select by class or '#' to select by id. If no '.' or '#' is specified, jQuery will try to find an element by tag name... in your case it was trying to find <infobubble> which isn't an element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM