Home > Article > Web Front-end > jquery Some instructions on the use of event.target_jquery
event.target
Description: The DOM element that triggered the event.
The difference between this and event.target
Events in js will bubble up, so this can change, but event.target will not change, it will always be direct The target DOM element that accepts the event;
The similarities between this and event.target
This and event.target are both DOM objects. If you want to use the methods in jquey, you can convert them into jquery objects: $(this) and $(event.target);
This reminds me of an example I wrote before:
<script><br>$(document).ready(function(){<br> function handler(event) {<br> var $target = $(event.target);<br> if( $target.is("li") ) {<br> $target.children().toggle();<br> }<br> }<br> $("ul").click(handler).find("ul").hide();//从这里也看出find只在后代中遍历,不包括自己。<br>});<br></script>
toggle has two functions:
toggle()
Switches the visible state of an element.
If the element is visible, switch to hidden; if the element is hidden, switch to visible.
toggle(fn,fn)
Toggle the function to be called each time it is clicked.
If a matching element is clicked, the specified first function is triggered, and when the same element is clicked again, the specified second function is triggered. Each subsequent click repeats the call to these two functions in turn.
Can be deleted using unbind("click").