Quantcast
Channel: Getting id of an element in jQuery using a function - Stack Overflow
Browsing all 6 articles
Browse latest View live

Answer by Regent for Getting id of an element in jQuery using a function

.click() is supposed to get Function, not String as parameter.It should be:$('#myButton1').click(myfunction);Fiddle.

View Article



Answer by Moob for Getting id of an element in jQuery using a function

When you click on myButton1 the JS is unable to dispatch the event and throws TypeError: undefined is not a function because you are calling it incorrectly. Your browser may however register the click...

View Article

Answer by Rahul Tripathi for Getting id of an element in jQuery using a function

Try this:-$('#myButton1').click(function(){ console.log(this.id);});

View Article

Answer by James Donnelly for Getting id of an element in jQuery using a function

Your #myButton2 example is accurate. You need to use this.id to get the ID of the element which the event has been fired on:$('#myDiv').click(function() { alert(this.id);});However this isn't clicking...

View Article

Answer by Rob Schmuecker for Getting id of an element in jQuery using a function

$('#myButton1').click(function(){myfunction(this)});myfunction = function(e){ alert(e.target.id); e.stopPropagation(); }

View Article


Getting id of an element in jQuery using a function

I have a simple code with two buttons in a div container. I want to get the id of a button using a function.Problem: Can someone please explain why clicking on Button1 doesn't alert myButton1? How can...

View Article
Browsing all 6 articles
Browse latest View live




Latest Images