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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post

    How to retrieve an XML node using one of its attributes

    Hello,

    I am trying to get the index of an XML node in an array by using an attribute. So, you can see where I create the span and set its name attribute using .url from the pages_arr. Then when a user cliscks on that span I am trying to refer back to the array using that name attribute.

    This is an array of objects with name value pairs.

    It doesn't seem like it should be this hard.

    Code:
    /* This function creates the tick marks and the listeners for the console page scrubber */
    function createScrubberTicks(){
    	for(i=0; i< pages_arr.length; i++){
    		$('#scrubberList').append('<li><span id="' + pages_arr[i].title + '" name="' + pages_arr[i].url + '" class="scrubberBtn">'</span></li>');
    	}
    
        $('.scrubberBtn')
            .click(function(){
    			$(this).removeClass("scrubberBtn").addClass("scrubberBtnSelected").parent().siblings().children().removeClass('scrubberBtnSelected').addClass('scrubberBtn');
    			alert(pages_arr.indexOf(this.getAttribute("name").parentNode));
    			alert(this.getAttribute("name").parent);
    			//requestPage(current_pg_ind);
            })
    }
    Last edited by m2244; 09-27-2012 at 09:49 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,696
    Thanks
    25
    Thanked 658 Times in 657 Posts
    First problem is this tick mark, Remove it:
    Code:
    $('#scrubberList').append('<li><span id="' + pages_arr[i].title + '" name="' + pages_arr[i].url + '" class="scrubberBtn">'</span></li>');
    forgot the ';' at end of click function.

    getAttribute is not part of jquery use attr
    Last edited by sunfighter; 09-28-2012 at 05:29 PM.


  •  

    Posting Permissions

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