Sithira Pathmila
Sithira Pathmila

Reputation: 145

How to refer My own custom attribute using jQuery

Please describe how to refer tag using my custom attribute using jQuery.

I have tag like this :

<a user="kasun" href="#" id="id1">Show More...</a>

I want to refer tag without refering id. like

 $('#id1')

I want to refer it like:

$('#user')//this is wrong. I mentioned this code only for understand what I mean.

Thank You.

Upvotes: 0

Views: 41

Answers (2)

Uvaise
Uvaise

Reputation: 309

I would agree with Amiros answer. I would like to give one more option to select those elements which are having custom attribute in ONLY anchor tags.

$("a[user]")

$("a[user='kasun']")

Upvotes: 0

Amir Popovich
Amir Popovich

Reputation: 29836

You can use:

$('[user]')

or

$('[user="kasun"]')

Fiddle

Upvotes: 2

Related Questions