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; } Link to comment https://forums.phpfreaks.com/topic/88981-solved-javascriptdiv-tags/ 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> Link to comment https://forums.phpfreaks.com/topic/88981-solved-javascriptdiv-tags/#findComment-455721 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. Link to comment https://forums.phpfreaks.com/topic/88981-solved-javascriptdiv-tags/#findComment-455737 Share on other sites More sharing options...
phpQuestioner Posted February 2, 2008 Share Posted February 2, 2008 client side or server side cookies Link to comment https://forums.phpfreaks.com/topic/88981-solved-javascriptdiv-tags/#findComment-455757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.