Reputation: 323
Following is my onclick event of class. All I am trying to do how to get an input too from html element on which the .slideto
being clicked.
E.g
<span class="slideto" input="4">
Click it and on click alert popup the input value
</span>
$(".slideto").click(function(){
alert(inputval);
});
Upvotes: 1
Views: 56
Reputation: 102783
Inside the handler, this
refers to the clicked element. So you just need:
alert($(this).attr("input"));
Upvotes: 2
Reputation: 9947
. to select by class and this refers to the current item
$(".slideto").click(function(){
var value = $(this).attr('input');
});
Upvotes: 0
Reputation: 2443
try this
$(".slideto").click(function(){
alert($(this).attr('input'));
});
Upvotes: 0
Reputation: 146310
You can do:
$(".slideto").click(function(){
alert($(this).attr('input'));
});
Upvotes: 2
Reputation: 104785
You should use data-*
for custom attributes
$(".slideto").click(function(){
alert($(this).data("input"));
});
And the HTML:
<span class="slideto" data-input="4">
Upvotes: 1