www.webdeveloper.com
Results 1 to 3 of 3

Thread: get integer of selected element

  1. #1
    Join Date
    Oct 2011
    Posts
    54

    get integer of selected element

    Hello,
    I want to know if there is a option that can tell you which element is selected of all the elements. My english isn't that great so let's get to the point:

    HTML Code:
    		<td>
    		<a class="menuTd" href="">Tech tutorials</a>
    		</td>
    		
    		<td>
    		<a class="menuTd" href="">All kinds of tutorails</a>
    		</td>
    		
    		<td>
    		<a class="menuTd" href="">About</a>
    		</td>
    
    var i = $(".menuTd").length;
    $("a.menuTd").hover(
    	function () {
    	    $("#underMenu").load("javascript/submenu/submenu" + i + ".html");
    		$("#underMenu").css("visibility","visible");
    	},
    	function () {
    		$("#underMenu").css("visibility","hidden");
    	}
    );
    If I hover the second .menuTd I want it to give me a number 2, if I hover over the third .menuTd I want a number 3. So I can load these other pages in.

    Thanks!

    HTML Code:
    var i = $(".menuTd").length;
    gives me the number 3 because there are 3 .menuTd, but I want it to give me the number that is hover.

    sorry for the bad description

  2. #2
    Join Date
    Feb 2011
    Posts
    231
    Hi,
    Try use the index() method.
    Example:
    Code:
    $('a.menuTd').click(
      // http://www.coursesweb.net/javascript/
      function () {
        var index = $('a.menuTd').index(this) + 1;
        alert(index);
        return false;
      }
    );

  3. #3
    Join Date
    Oct 2011
    Posts
    54

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles