-2

I want to change the background color of a single HTML page ( ex. contact.html ) but without changing the color of the other pages with jquery. Propably I must make an if statement in order to check the url and change the color, but I can't find how.

Thank you in advance.

1 Answers1

0

I guess you use the same script in all your pages?

This way you can check what page the script is currently running in:

if (document.location.pathname.match(/[^\/]+$/)[0] == 'contact.html') {
    //... do what ever you only want to do if it's contact.html
    $('body').css("background-color", "yellow");
}

Solution from Jquery to get the name of the current html file

Community
  • 1
  • 1
JPS
  • 411
  • 6
  • 16