user2304394
user2304394

Reputation: 323

.click of class get an input too

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

Answers (5)

McGarnagle
McGarnagle

Reputation: 102783

Inside the handler, this refers to the clicked element. So you just need:

alert($(this).attr("input"));

(Fiddle)

Upvotes: 2

. to select by class and this refers to the current item

$(".slideto").click(function(){
var value = $(this).attr('input');
});

Upvotes: 0

Shivam
Shivam

Reputation: 2443

try this

$(".slideto").click(function(){
    alert($(this).attr('input'));
});

Upvotes: 0

Naftali
Naftali

Reputation: 146310

You can do:

$(".slideto").click(function(){
    alert($(this).attr('input'));
});

Upvotes: 2

tymeJV
tymeJV

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

Related Questions