whether possible so?
<div id="search"> <div id="elem"></div> </div> <div id="search2"> <div id="elem"></div> </div>
------this example i`m trying do--------
$('#search').ready(function(){//i want declare parent elem $('#elem').html('some');//make actions inside parent elem }); $('#search2').ready(function(){//i want declare parent elem2 $('#elem').html('some2');//make actions inside parent elem }); //or possible that: $('#search #elem').html('some'); $('#search2 #elem').html('some2');
let's start basics: first of all, shouldn't have duplicate id
s, the id
attribute should unique, , hence shouldn't have problem of identifying target referring to.
secondly, there no such thing in jquery $(element).ready()
, ready()
method fired when dom in entirety loaded , ready manipulated.
thirdly, question, can narrow down selectors make sure targeting children of specific element using .find()
, such:
html
<div id="search"> <div class="elem"></div> </div> <div id="search2"> <div class="elem"></div> </div>
js
jquery(document).ready(function($){ $('#search').on('click', function(){ $(this).find('.elem').html('some'); }); $('#search2').on('click', function(){ $(this).find('.elem').html('some2'); }); });
Comments
Post a Comment