Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically change the class according to the variables

 
Sumer Selvaraj
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm developing a Web application. As you see the picture I kept the menus as tabs in a separate file and called it to the main page using code.


there is no issue in it. I wanted to change the tabs classes according to the variables in the URL. I gave a try with javascript & jquery but it didn't work.

Banner File


Javascript File


I want to change add the current class the tabs which selected. Can some one help on this???
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64836
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At what point is it going wrong? Are the "parts" as you expected after the regex? Why are you using the replace() method?

Open the debugging console in your browser and set breakpoints in the code. That way you can look at the value of variables and find out at what point it is going wrong. Why guess when you can actually inspect the variable at run time?
 
Sumer Selvaraj
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:At what point is it going wrong? Are the "parts" as you expected after the regex? Why are you using the replace() method?

Open the debugging console in your browser and set breakpoints in the code. That way you can look at the value of variables and find out at what point it is going wrong. Why guess when you can actually inspect the variable at run time?


There is no issue in getUrlVars() method. It returns the URL variables. I'm quite sure there is something wrong with the code
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64836
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please make sure that the code you post is properly indented.

Did you open the debugging console? What error messages did you get?
 
Sumer Selvaraj
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Please make sure that the code you post is properly indented.

Did you open the debugging console? What error messages did you get?


I've got the following error message on the console

Uncaught TypeError: Object #<HTMLUListElement> has no method 'removeClass' common_javascript.js:8
Got message from bg page - https://mail.google.com/mail/?view=cm&fs=1&tf=1 mailto.js:51
Starting to rewrite mailtos
 
Sumer Selvaraj
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Please make sure that the code you post is properly indented.

Did you open the debugging console? What error messages did you get?


Further I have changed the script as follows


And now I am getting error as : "Uncaught ReferenceError: element is not defined"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64836
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elements do not have an addClass method. You need to wrap the element with jQuery to use jQuery methods. E.g. $(element).addClass()
 
Sumer Selvaraj
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Elements do not have an addClass method. You need to wrap the element with jQuery to use jQuery methods. E.g. $(element).addClass()


Thank you. I worked
 
Sumer Selvaraj
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found a solution for this problem. I was coming around the bush. Now I've hit the bush. The following code helped me to overcome this issue

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic