[英]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 我如何使用jQuery来定位
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")
将寻找一个不存在的名为infobubble
的标记元素
$(".infobubble p").html('My Text');
in jQuery you need to add an '.' 在jQuery中,您需要添加“。” to select by class or '#' to select by id.
按类别选择,或按“#”按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. 或指定了“#”,jQuery将尝试通过标签名称查找元素...在您的情况下,它试图查找不是元素的
<infobubble>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.