0

I need to add a tag to the existing id , the current HTML is

<div id="home" class="pagebody"></div>

and i need to add an additional class to the pagebody ONLY if the url has "MODULE=" in it.

So when the url contains "MODULE=" , the appended html will look like this

<div id="home" class="pagebody hpmessage"></div>

I don't have access to the HTML to manually change this , so i have to use JavaScript / jquery to add the additional class and it must only be added to those urls containing "MODULE=" , any ideas ?

examples of some of the vast URLs are:

http://mysite/2014/home/20832
http://mysite/2014/home/20832/standings
http://mysite/2014/home/20832?MODULE=MESSAGE
http://mysite/2014/home/20832?MODULE=MESSAGE1
http://mysite/2014/home/20832?MODULE=MESSAGE2
code-jaff
  • 9,230
  • 4
  • 35
  • 56
MShack
  • 642
  • 1
  • 14
  • 33

2 Answers2

4
if ( window.location.href.indexOf('MODULE=') != -1) {
    $('#home').addClass('hpmessage')
}

Get the current location, check if it contains MODULE-, and if so add a class ?

adeneo
  • 312,895
  • 29
  • 395
  • 388
0

Vanilla JS version:

if ( window.location.search.indexOf( 'MODULE=' ) > -1 )
    document.body.classList.add( 'hpmessage' );
Shomz
  • 37,421
  • 4
  • 57
  • 85