Jump to content

[SOLVED] Javascript/Div tags


ShaolinF

Recommended Posts

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

 

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.