Thanks, I ended up playing around with the url before I passed it into
the function, didn't realise I could do it like that.

On Feb 25, 7:49 pm, brian <bally.z...@gmail.com> wrote:
> Also, $($finalurl) likely won't select anything because you're only
> passing the classname. It needs to be in the form '.classname'
> (prepended by a dot). Try $('.'+$finalurl)
>
> On Wed, Feb 25, 2009 at 2:38 PM, Stephan Veigl <stephan.ve...@gmail.com> 
> wrote:
>
> > Hi,
>
> > instead of doing a complicate string handling you could simply use
> > window.location.hash:
>
> > $finalurl = window.location.hash;
>
> > For debugging I would do it step by step and not all in one line:
>
> > var el = $($finalurl+" :first");
> > var src = el.attr("src");
> > var src_split = src.split(".");
> > var new_src = src_split.join("_on.");
> > el.attr("src", new_src);
>
> > This way you can use firebug to step through your code and see which
> > statement produces the error.
>
> > by(e)
> > Stephan
>
> > 2009/2/25 digital <michael.digital.b...@googlemail.com>:
>
> >> Hi, pulling my hair out here.
>
> >> When the page loads I'm collecting a variable from the url which
> >> corresponds to the class of an image. I want to then change the image
> >> source. I'm doing this because the page doesn't reload and the menu
> >> needs to respond to the content if you get my meaning.
>
> >> $url = location.href;
> >> $hashtag = $url.search(/#/)
> >> $url2 = $url.split("#", $hashtag);
> >> $finalurl = $url2[1];
>
> >> This is the code I use to get the class name. When I try to add
> >> $finalurl to the attr (see below) it throws an error (undefined,
> >> console.log shows it is defined within the if statement).
>
> >> $($finalurl).attr("src", $($finalurl).attr("src").split(".").join
> >> ("_on."));
>
> >> Full code:
>
> >> $url = location.href;
> >> $hashtag = $url.search(/#/)
> >> $url2 = $url.split("#", $hashtag);
> >> $finalurl = $url2[1];
>
> >> counttemp = 0;
>
> >> if (counttemp == 0) {
> >>        console.log($finalurl);
> >>        $($finalurl).attr("src", $($finalurl).attr("src").split(".").join
> >> ("_on."));
> >>        counttemp = countemp + 1;
> >> }
>
> >> Any help would be greatly appreciated.

Reply via email to