target
UK[?tɑ:g?t] US[?tɑ:rg?t]
n. Target; purpose; (service) object; (shooting) Target
vt. Aim; take... as an attack target
jquery target attribute syntax
Function:The target attribute specifies which DOM element triggered the event.
Syntax: event.target
Parameters:
Parameters | Description |
event | Required. Specifies the events that need to be checked. The event parameter comes from the event binding function. |
jquery target attribute example
<html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p, button, h1, h2").click(function(event){ $("div").html("點擊事件由一個 " + event.target.nodeName + " 元素觸發(fā)"); }); }); </script> </head> <body> <h1>這是一個標題</h1> <h2>這是另一個標題</h2> <p>這是一個段落</p> <button>這是一個按鈕</button> <p>標題、段落和按鈕元素定義了一個點擊事件。如果您觸發(fā)了事件,下面的 div 會顯示出哪個元素觸發(fā)了該事件。</p> <div></div> </body> </html>
Click the "Run instance" button to view the online instance