Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Dynamically change the class according to the variables

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
reply
    Bookmark Topic Watch Topic
  • New Topic