If for the sake of argument I'm applying a class to a <p>
and an <a>
and I then want to determine whether it was an <a>
or a <p>
that was clicked, is there a way to do it?
Example of intended use:
$(".selector").click(function(){
element = $(this).whatElementWasClicked(); // return "a" or "p"
}
Use the querySelectorAll() method to get all elements by type, e.g. document. querySelectorAll('input[type="text"]') . The method returns a NodeList containing the elements that match the provided selector.
The typeof operator when applied to the jQuery object returns the string "function" . Basically that does mean that jQuery is a function. But the typing sort of stops there.
$() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements. Most of the time you will need to start with $() function. It is advisable to use jQuery after DOM is loaded fully.
Use something like this:
$(".selector").click(function(event){
var element = event.target.nodeName }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With