Problem with Jquery addClass?

Just a guess, your anchor has an href and when clicked, it reloads the page, try changing code like below.

Thats a good guess, I always forget to change the href thing. – Thomas Apr 29 at 7:56 @Thomas: Even better: If you don't use the link as link, meaning it does not refer to another site, use a button. – Felix Kling Apr 29 at 7:57.

Apparently, by adding the code before the tag, the script wouldn't work. I moved the code below the tag and everything works fine. Thanks for all the suggestions!

1 It should work, because you are passing a callback to the document. Ready event. I.e.

The code is run after the DOM is loaded. Or maybe this is not the code you have? In my jsfiddle example you can see that the code is added to the head of the page (i.e.

Before the elements) and it works. – Felix Kling Apr 29 at 8:05 I didn't use document. Ready - thats why it needed to be loaded after the content.

Thanks for helping me flush it out. – Thomas May 1 at 9:17 Well, in your code you do. $(function(){...}) is a shortcut for $(document).

Ready(function(){...}). But anyway.... – Felix Kling May 1 at 13:44.

Include javascript:void(0); in your href to prevent any navigation ..

I think this is what you're trying to do, with comments so hopefully you learn something about Javascript/jQuery.

I think this is what you're trying to do, with comments so hopefully you learn something about Javascript/jQuery: // when DOM is ready $(function(){ // cache current URL var current_page = document.location. Href; // use . Each method to check link hrefs against current location $("ul#sol_menu li a").

Each(function () { // if this link is for the current page, highlight it if (current_page. IndexOf(this. Href) >= 0) { $(this).

AddClass('highlight'); }; }); }).

I believe this might be what you were going for... And as SLaks pointed out, your syntax (in this case) is a bit atrocious... So to answer your question... the following was wrong with your code: Depending whether or not your script tag was before or after your ul element, you need to use the $(document). Ready function You weren't using the addClass callback properly... You had an extra bracket at the addClass callback "addClass(function()) {" should have been "addClass(function() {" There's no . Match method like the one you've used... You had a syntax error here: '.attr.("href")'; no period after '.

Attr' Hope that answers your question.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions