How do I get the whole segment of Location Address including the address, city state and ZIP inside of a span which is inside another div in jquery?
<div class="EachLocation" style="width:225px;float:right;position:relative; border-bottom:1px dotted silver;">
Munster Women's Center<br />
<span class="LocationAddress">1455 Sycamore Blvd.<br>Munster,IN 42103</span>
<br>(219) 232-7601<br><br>
</div>
Try the following
var text = $('div.EachLocation span.LocationAddress').text();
Note: If there is more than one set of DOM elements which matches that selector then the text returned will be the combined contents of all of them.
How about?
$('.LocationAddress').text();
It doesn't matter where it's at in the DOM tree, unless you actually want to limit its scope to one parent or another. If you want to preserve the <br/>
as well, use .html()
instead of .text()
.
UPDATE
So, in truth, you most likely want each .EachLocation
's address and not just the first. So it should really be something like:
$('.EachLocation').each(function(){
$('.LocationAddress', this).text();
});
最简单的方法是将id
赋予span
,然后获取value
或html
所需要的value
,例如,如果span id
设置为locationaddress
$('#locationaddress').html();
使用JQuery:
$('div.EachLocation span.LocationAddress').html()
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.