...

View Full Version : How to retrieve an XML node using one of its attributes



m2244
09-27-2012, 08:47 PM
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.



/* 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);
})
}

sunfighter
09-28-2012, 05:19 PM
First problem is this tick mark, Remove it:

$('#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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum