I have a list of div on a parent function, each does a onclick function.
How can I make a function that I can have a function to get the first div and run the onclick function?
The important thing is, my divs can be sorted. So after being sorted, the “first div” might not be the first anymore, so I need a function to be defined and each time when window is ready I run it once, and after the divs are sorted I run it again.
Thanks!
Edit: OK, say here’s my code, I will sort those divs based on the id:
<div id="e">
<div id="e1" onclick="$(this).siblings().removeClass('someclass').addClass('someclass')">Something</div>
<div id="e2" onclick="$(this).siblings().removeClass('someclass').addClass('someclass')">Something</div>
<div id="e3" onclick="$(this).siblings().removeClass('someclass').addClass('someclass')">Something</div>
<div id="e4" onclick="$(this).siblings().removeClass('someclass').addClass('someclass')">Something</div>
<div id="e5" onclick="$(this).siblings().removeClass('someclass').addClass('someclass')">Something</div>
</div>
Use delegate with
firstselector.Note: Specify the appropriate selector for
divsContainerwhich is actually the contianer in which all these divs are present.