[英]jQuery get HTML contents of child DIV
Not sure why I cannot get this to work.不知道为什么我不能让它工作。 Tried a few permutations now.
现在尝试了一些排列。
I have built a JSFIDDLE here .我在这里建立了一个JSFIDDLE 。
I cannot get this jQuery to return the inner HTML for the target element.我无法让这个 jQuery 返回目标元素的内部 HTML。 Is it because of the number child elements in the hierarchy?
是因为层次结构中的子元素数量多吗?
jQuery: jQuery:
modalContentLeft = 'Project: ' + $('#mob-' + uuid + ' div.project-name').html();
I have also tried using .find()
without success.我也尝试使用
.find()
没有成功。 Thanks for any help.谢谢你的帮助。
I found your fault: you are closing the div tag of the id before it gets to the name.我发现了你的错:你在到达名称之前关闭了 id 的 div 标签。 You are closing it before the class
<div class="mobile-item-row clearfix">
, so the selector does not find the children ".project-name"
in it,because there is none.您在
<div class="mobile-item-row clearfix">
之前关闭它,因此选择器在其中找不到子项".project-name"
,因为没有。 if you remove the closing tag and close it at the end of the HTML and change the syntax of the selector a bit, it works.如果您删除结束标记并在 HTML 末尾关闭它并稍微更改选择器的语法,则它可以工作。
Project: ' + $('#mob-'+uuid+' .project-name').html()
Here you go: https://jsfiddle.net/ucupbtsf/5/给你: https : //jsfiddle.net/ucupbtsf/5/
First your post here and your jsfiddle don't reflect the same...首先你在这里的帖子和你的 jsfiddle 反映的不一样......
JsFiddle : JsFiddle :
modalContentLeft = 'Project: ' + $('#mob-' + uuid + ' div div .project-name').html()...
Here :这里 :
modalContentLeft = 'Project: ' + $('#mob-' + uuid + ' div.project-name').html();
Then, your html is :然后,您的 html 是:
<div class="mobile-item-row-first first-row clearfix" id="mob-6c985947-c68a-4f5b-9ebe-0d488b696f0d">
<div class="project-client pull-left">
<i class="ion-ios-people ion-fw" data-original-title="" title=""></i> Sienna Cremin
</div>
</div>
which does not reflect your jquery selector :这不反映您的 jquery 选择器:
$('#mob-' + uuid + ' div div .project-name').html()
Seems you closed too much div, so your .project-name div is not in the #mob-id div.似乎您关闭了太多 div,因此您的 .project-name div 不在 #mob-id div 中。
$(elem).html()
will get you all the content of the div (including the <i></i>
part). $(elem).html()
将获得 div 的所有内容(包括<i></i>
部分)。 If you only want the text, you can go for $(elem).text()
.如果你只想要文本,你可以去
$(elem).text()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.