SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict dr_dumb99's Avatar
    Join Date
    Sep 2004
    Location
    Pakistan
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Li id is not shown through jQuery attr selector

    Hi!
    I have following HTML code:
    Code:
    <div id="nav" class="width_main last">
              <ul>
              		<li><a href="#" id="nav_home">HOME</a></li>
              		
    				<li><a href="#" id="nav_about">ABOUT GP</a>
    					  <ul id="nav_about_sub" class="tab">
    						<li><a href="#">about</a></li>
    						<li><a href="#">about</a></li>
    					  </ul>
    				</li>
              
    		  		<li><a href="#" id="nav_solution">SOLUTIONS</a>
    					  <ul id="nav_solution_sub" class="tab">
    						<li><a href="#">solutions</a></li>
    						<li><a href="#">solutions</a></li>
    					  </ul>
    				</li>
    				
    				<li><a href="#" id="nav_service">SERVICES</a>
    					  <ul id="nav_service_sub" class="tab">
    						<li><a href="#">services</a></li>
    						<li><a href="#">services</a></li>
    					   </ul>
    				</li>
              		
    				<li><a href="#" id="nav_contact">CONTACT US</a></li>
              </ul>
    	   </div>
    And following is my jQuery code:
    Code:
    <script language="javascript" type="text/javascript">
    
    jQuery(document).ready(function(){
    		
    		jQuery('li[id^="nav_"]').bind('click', function(){
    			
    			alert(jQuery(this).attr('id'));
    		});
    
    });
    </script>
    The alert is not working. Can some one guide me where Iam doing wroing.

    Thanks in advance

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,080
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    The <a> tags have id's starting with nav_ in your HTML, not the <li>'s
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

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