I was wondering how I will search with jQuery, an identifier for an element called the onClick method? my code is:
Js
function getInfo(event) { console.log(event.target.id + " ... "); }
HTML
<div class="menu-content" id="thisismyid"> This is some placeholder text.<br> <a onClick="getInfo()" id="thisisthelinksid">Click on me</a> </div> <div class="menu-content" id="thisismysecondid"> This is some more placeholder text.<br> <a onClick="getInfo()" id="thisistheotherlinksid">Click on me</a> </div>
I cannot put anything inside the parentheses of a function, because I want the function to be passed in later, I just want to say who called this function.
I know that this has been asked many times, and many questions have answers, but I read them a lot, and none of them helped me.
Thanks guys,
-Edit -
As for the answers below during this edit, I cannot use the jQuery method, for example:
$("div.menu-content a").click(function() { some content here.. });
because I need it to run only on certain clicks, and not on all. Did this clarification help?
source share