Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This topic is solved. following is the solution.

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

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,486
    Thanks
    6
    Thanked 981 Times in 954 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •