问题
I have a listing of DIVs in my CMS HTML Page where I want to know the value of the ID of a child DIV.
As an example, here is the HTML :-
<div class="view" id="views_slideshow_cycle_div_resources-block_3">
<div class="views-slideshow-cycle">
<div class="content clearfix">
<div class="field-item even">
<div class="jwplayer-video">
<div id="4ac1a678934a37fd58e86cf0a7d51c79_wrapper">
<object></object></div>
What I need to know is the value of ID of DIV inside of DIV with class=jwplayer-video, which is "4ac1a678934a37fd58e86cf0a7d51c79_wrapper"
What I tried to do is:-
$("#views_slideshow_cycle_div_resources-block_0").find(".jwplayer-video")
or even this
$("#views_slideshow_cycle_div_resources-block_0").find(".jwplayer-video").attr("id")
Unfortunately, it doesn't help.
Any help please.
Thanks.
回答1:
$("#views_slideshow_cycle_div_resources-block_3 .jwplayer-video div:first").attr("id");
回答2:
Try this
$('#views_slideshow_cycle_div_resources-block_3').find('div.jwplayer-video').find('div').eq(0).attr('id');
I created a jsfiddle for your help.
回答3:
$("#views_slideshow_cycle_div_resources-block_3").find(".jwplayer-video").children().attr('id')
jsFiddle example
回答4:
$("#views_slideshow_cycle_div_resources-block_0").find(".jwplayer-video").children().attr("id");
The .jwplayer-video div does not have an ID. You must go one step deeper.
Also take a look at the Id in HTML and jQuery
block_0 and block_3
回答5:
Try
$(".jwplayer-video").children().attr("id")
来源:https://stackoverflow.com/questions/15667861/find-value-of-a-children-div-id-inside-another-div