CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   Get li attribute using javascript or jquery. (http://www.codingforums.com/showthread.php?t=280794)

zohaib82 11-04-2012 06:13 AM

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 11-04-2012 07:55 AM

This topic is solved. following is the solution.

http://tech.avivo.si/tag/jquery-get-attribute-value/

VIPStephan 11-04-2012 02:34 PM

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.


All times are GMT +1. The time now is 10:20 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.