ShaolinF Posted February 1, 2008 Share Posted February 1, 2008 Hi Guys, I have some js and a div tag with a class property. Now when the user clicks a link the javascript should change the div tag class property, in this case, from setnone to setdisplay (css properties). But when I click the link, the content between the div tag displays but only for a fraction of a second and then disappears. See code below: HTML <a href="" onmouseup="changeClass();">Edit Events</a> <div id="eventsetting" class="setnone"> //stuff in here </div> Javascript function changeClass() { setClassName("eventsetting","setdisplay"); } function setClassName(targetName, nameOfClass) { var target = document.getElementById(targetName) if(document.implementation && document.implementation.createDocument) { target.setAttribute("class", nameOfClass); } else { target.className = nameOfClass; } } CSS .setnone { display : none; } .setdisplay { display : inline; } Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted February 2, 2008 Share Posted February 2, 2008 It's because you are not define your href location; so it just reloads you page. try it this way: <style type="text/css"> .setnone { display : none; } .setdisplay { display : inline; } </style> <script language="javascript"> function changeClass() { setClassName("eventsetting","setdisplay"); } function setClassName(targetName, nameOfClass) { var target = document.getElementById(targetName) if(document.implementation && document.implementation.createDocument) { target.setAttribute("class", nameOfClass); } else { target.className = nameOfClass; } } </script> <a href="javascript://" onmouseup="changeClass();">Edit Events</a> <div id="eventsetting" class="setnone"> stuff in here </div> Quote Link to comment Share on other sites More sharing options...
ShaolinF Posted February 2, 2008 Author Share Posted February 2, 2008 Thanks. How could I save this option so even on page refresh the content doesnt disappear ? Only if another link is clicked does the content dissapear. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted February 2, 2008 Share Posted February 2, 2008 client side or server side cookies Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.