What I want to do is a small button that when you click it, a new div appears, like in this page:
When you click the red "View Schedule" button. Is any way to do this with CSS and HTML? or do I need to use Javascript?
What I want to do is a small button that when you click it, a new div appears, like in this page:
When you click the red "View Schedule" button. Is any way to do this with CSS and HTML? or do I need to use Javascript?
Yes, click events are JavaScript. You can do hover events without JavaScript using CSS, but the manipulation has to be on the element with which the mouse is interacting:
#myDiv {
background-color: blue;
}
#myDiv:hover {
background-color: red;
}
Check out jQuery. Your task can be done super easily:
$('#myButton').on('click', function() {
$('#someOtherDiv').show();
}
I'm going to get a lot of "semantic HTML" responses, but whatever. You can totally do this with just HTML / CSS (catch: it only works for IE9+ and all real browsers ... for IE8-, JS it is).
The HTML:
<label for="checkbox" id="checkboxLabel">Show More</label>
<input type="checkbox" id="checkbox" />
<div id="stuffToShow">
Happy times
</div>
The CSS:
#stuffToShow {
display:none;
}
#checkbox {
opacity:0.01;
}
#checkbox:checked + #stuffToShow {
display:block;
}
You can then style the label
and checkbox
however you'd like: this is an incredibly simplistic version of what you can / should do.
EDIT (2013-06-10)
Just because no one is willing to show this in basic JS, the old-school HTML4 way:
<a href="#" id="ShowDiv" onclick="showHideDiv('ShowMoreDiv');">Show More</a>
<div id="ShowMoreDiv">
Boo
</>
And the Vanilla JS:
function showHideDiv(div){
var x = document.getElementById(div);
if(x.style.display == 'none'){
x.style.display = 'block';
} else {
x.style.display = 'none';
}
return false;
}
This is also somewhat unsemantic in my opinion because you have a link that takes you no where, but there ya go.