> From: SteelSoftware > > I'm having trouble with a bit of jQuery. It seems that if I include > the following lines into my code, the page follows the link that i'm > clicking instead of staying on the same page: > > var $ref = $("#calendar .#navleft").attr("href").text(); > $("#calendar .nav").attr("href", $ref.substring(0, > ($ref.length-1)).append('1')); > > What this should do is find the HREF of the anchor and change the last > character to a 1. I have to do this twice per query (as there are two > links to be changed). Firebug tells me the JS is fine, but I believe > it's something to do with the presence of the substring which makes > return false fail.
Could you post a link to a test page? It's pretty hard to tell what the problem might be from your code snippet. Hmm... I do see a problem (unnecessary parentheses removed for clarity): $ref.substring( 0, $ref.length-1 ).append( '1' ) Strings don't have an append() method. That code will throw an exception. Doesn't Firebug complain about that? The exception will stop JavaScript execution, which could be your problem right there. A simpler way to code that would be: $ref.slice( 0, -1 ) + '1' Whoa... Backing up a bit... The first line of code looks wrong too: var $ref = $("#calendar .#navleft").attr("href").text(); What kind of selector is ".#navleft"? I don't think that would work. Also, when you get the "href" attribute, you're getting a text string. Strings don't have a .text() method either. So that first line of code will throw an exception. Maybe you should describe in English exactly what you want to do. :-) -Mike