dotNet Zombie
dotNet Zombie

Reputation: 134

jQuery code not working in Firefox/Chrome

var matcheduserID = $('.checkone')[1].matcheduserID;

<input type="checkbox" matcheduserID='user1' class="checkone" onclick="javascript:HoldItem('H')"> 

This code works in Internet Explorer, though in Firefox and Chrome I get it returns undefined.

Upvotes: 0

Views: 108

Answers (2)

Sushanth --
Sushanth --

Reputation: 55750

I think you are trying to access the wrong element in the first place.. Are you trying to access the First element or the second element ..

The NodeList is 0 index based.

If it's the first element you are trying to access then use

var matcheduserID = $('.checkone')[0].matcheduserID;

Try using the .getAttribute() method

.get(1) gets the second element with the given class..

var matcheduserID = $('.checkone').get(1).getAttribute("matcheduserID");

Maybe you are encountering this issue because matcheduserID is not a default attribute for the element

jQuery

var matcheduserID = $('.checkone:eq(1)').attr('matcheduserID'); 

Upvotes: 2

srijan
srijan

Reputation: 1522

I think you are trying to do this

matcheduserID = $('.checkone:first').attr('matcheduserID');

Upvotes: 2

Related Questions