Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-04-2012, 06:13 AM   PM User | #1
zohaib82
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
zohaib82 is an unknown quantity at this point
Question Get li attribute using javascript or jquery.

Hi,

I want to get url attribute of li when user click on li.

Code:
<ul>
	<li url="http://www.google.com" id="1">Google</li>
	<li url="http://www.yahoo.com" id="2">Yahoo</li>
	<li url="http://www.bing.com" id="3">Bing</li>
	<li url="http://www.facebook.com" id="4">Facebook</li>
	<li url="http://www.amazon.com" id="5">Amazon</li>
</ul>
I found following but no idea how it will work

Code:
$('li').click(function() {
    alert($(this).data('url'));
});
Any idea how to get li url value when click using javascript or jquery?

- Thanks
Zohaib.
zohaib82 is offline   Reply With Quote
Old 11-04-2012, 07:55 AM   PM User | #2
zohaib82
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
zohaib82 is an unknown quantity at this point
This topic is solved. following is the solution.

http://tech.avivo.si/tag/jquery-get-attribute-value/
zohaib82 is offline   Reply With Quote
Old 11-04-2012, 02:34 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,703
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
By the way: There is no url attribute for the li element in any current version of HTML. And also, IDs must not start with a number. They have to begin with any letter a-z or A-Z.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:53 AM.


Advertisement
Log in to turn off these ads.