Reputation: 1
I have a HTML with with a paragraph and a contact form. When the browser has JavaScript disabled I want to show contact form and paragraph of text.
Otherwise, I want to show the contact button, which users can click and the form shows up.
Upvotes: 0
Views: 90
Reputation: 1662
Ok :) So here's my solution:
http://jsfiddle.net/tracyfu/Sj5cy/
And here's what it does:
#contact-button
css to display: none;
so that it's automatically hidden whether or not JS is present. This way if JS is disabled, the button doesn't show up.#contact-button
, then I hide #contact-form
. JQuery will only work when JS is enabled anyway, so what this does is show the button and hide the form for people who have JS. For people who have JS disabled, the form is not affected and will show up like usual.click
event to the button to show the form.The goal of this solution is so that there isn't a button if JS is disabled.
Upvotes: 0
Reputation: 171411
<span id="formAndParagraph">
<p id="Paragraph">lorem ipsum lorem ipsum lorem ipsum lorem ipsum </p>
<form id="Contact">
Name: <input type="text"><br>
Comment: <input type="text"><br>
</form>
</span>
<input type="button" id="Button" value="Click me" onclick="$('#formAndParagraph').show();" style="display:none">
<script>
$('#formAndParagraph').hide();
$('#Button').show();
</script>
Upvotes: 0
Reputation: 7388
Set the button's style to display:none;
If javascript is enabled, hide the form by default and show the button.
Then when they click the contact button, show it.
$(document).ready(function(){
$("#buttonID").show();
$("#formID").hide();
$("#buttonID").click(function(){
$("#formID").show();
});
});
Upvotes: 1