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
  • 8,960
  • 4
  • 32
  • 56
MShack
  • 820
  • 1
  • 12
  • 30

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
  • 303,455
  • 27
  • 380
  • 377
0

Vanilla JS version:

if ( window.location.search.indexOf( 'MODULE=' ) > -1 )
    document.body.classList.add( 'hpmessage' );
Shomz
  • 36,910
  • 3
  • 55
  • 83