javascript - .nextAll not working on dynamic content -
this block of code within post request. json reply stored in 'data'
var a=data.data.overview; var b=data.data.extras; //summary var result=''; result+='<div class="extra-upper-block">'; result+='<h5 class="extra-head"><i class="'+b[0].icon+' extra-head-icons"></i> '+b[0].category+'<i class="fa fa-pencil edit-prof"></i></h5>'; result+='<div class="extra-sub-block">'; if(b[0][0].summary!=null) result+='<p id="profile-summary" class="extra-sub-block-summary">'+b[0][0].summary+'</p>'; result+='</div>'; result+='</div><hr class="extra-upper-block-separator">'; $('#profile-extras').append(result); this works fine. want click <p> tag on clicking
<i class="'+b[0].icon+' extra-head-icons"></i> these codes tried
$('.edit-prof').nextall('.extra-sub-block-summary:first').click(); $('.edit-prof').nextall('p:first').click(); $('.edit-prof').nextall('div > .extra-sub-block-summary:first').click(); nothing works. why p not getting selected? executing script after dynamic content loaded.
here fiddle http://jsfiddle.net/4pc3e/
you should utilize event delegation that
$(document).on("click",".extra-sub-block-summary:first",function(){ }); event delegation allows attach single event listener, parent element, fire children matching selector, whether children exist or added in future.
edit
|the way getting element wrong. seek code
$('.edit-prof').closest("h5").next(".extra-sub-block").find(".extra-sub-block-summary:first").click(); fiddle
javascript jquery html
No comments:
Post a Comment