This allows you to extract the actual DOM element and operate on it directly  without necessarily using jQuery functionality on it. This function called as  $(this).get(0) is the equivalent of using square bracket notation on the jQuery  object itself like $(this)[0].
Access the element in the Nth position
Example:
   
Access the element in the Nth position
Example:
Gives the tag name of the element clicked on.
$("*", document.body).click(function (e) {
      e.stopPropagation();
      var domEl = $(this).get(0);
      $("span:first").text("Clicked on - " + domEl.tagName);
    });
<span> </span>
  <p>In this paragraph is an <span>important</span> section</p>
  <div><input type="text" /></div>
span { color:red; }
  div { background:yellow; }
 
 
No comments:
Post a Comment