javascript - how do I add class of div from other page? -


i want remove class of div id other page anchor link.

firstpage.html

<div class="question show" id="a1"> sample 1 </div>  <div class="question" id="a2"> sample 2 </div> 

list.html

$(function () {               $("a").click(function () {                  $("#a2").addclass('question show');                              });            });      </script> </head> <body> <a href="firstpage.html#a1">link 1</a> <a href="firstpage.html#a2">link 2</a> </body> 

i want add class addclass('question show') div id clicked.

i tried here link1 id=a1

but i'm failed set class ('question show') me correct code please check code here http://plnkr.co/edit/fzdfjdrrbcwmir5whcjw?p=preview

i'm taking different approach. i'll not add function list.html. let page firstpage.html called value. capture anchor firstpage.html.

also, since divs have class 'question'; i'm ignoring class , targeting 'show' class.

so, load function firstpage.html:

$(document).ready(function(){     var call = $(location).attr('href').split('#');     var ancr = $.trim(call[1]);     if(ancr === undefined || ancr == ''){         // anchor not set, nothing     } else {         if (!$('#'+ancr).hasclass('show')) {             $('#'+ancr).addclass('show');         }     } }); 

i assume don't have multiple divs same id (which should not be).

i hope need.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -