javascript - Get parent class and trigger in jquery -
i want trigger event of parent class clicking button or image.
<li class="addimage"> <input class="photopicker" type="file" accept="image/*" capture="camera" onchange="angular.element(this).scope().file_changed(this)" /> <a class='imageclick' onclick=" $(this).closest('.photopicker').trigger('click');"> <img ng-src="images/add-photo.png"> </a> here addimage class repeated , when click on imageclick class, want trigger photopicker of respective list. working when use,
('.photopicker').trigger('click'); kindly me guys!
they not ancestors/descendants of each other.
you need go li (nearest common ancestor) using closest search down find:
$(this).closest('li').find('.photopicker').trigger('click'); you can shorten trigger('click') .click() same thing behind scenes:
$(this).closest('li').find('.photopicker').click(); you use sibling selector, not robust changes being made in dom. safer use common ancestor , find. example, if layout changed styling purposes , divs added around elements, sibling searches fail.
Comments
Post a Comment