0

First, sorry for my english, i´m a brazilian boy and new with javascript, and i try to make the id=termsjust hide in the site. I just don´t know what to do anymore.

Any help will be useful

The code is this

<div id="term">
	<p>
		Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
	</p>

	<button id="accept" type="submit" name="accept">Accept the terms of this site</button>
	
</div>

<script>
	$("#accept").click(function(){
	    $("#term").hide("fast");
	});
</script>

3
  • You have the same problem as this guy. Commented Jan 6, 2016 at 20:53
  • Check your console for errors : Uncaught ReferenceError: $ is not defined , which means jQuery is not defined. You forgot to add a reference for the jquery library. Commented Jan 6, 2016 at 21:00
  • Submit submits the form so that means when the page reloads the element will show up again. Commented Jan 6, 2016 at 21:01

4 Answers 4

1

You have to add a link to your jQuery.js file

<div id="term">
	<p>
		Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
	</p>

	<button id="accept" type="submit" name="accept">Accept the terms of this site</button>
	
</div>

<script src="http://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
	$("#accept").click(function(){
	    $("#term").hide("fast");
	});
});
</script>

Sign up to request clarification or add additional context in comments.

Comments

1

Did you Include jquery ? Wrap your function in DOM Ready $(function(){.. });

$(function() {
  $("#accept").click(function() {
    $("#term").hide("fast");
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="term">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
  </p>
  <button id="accept" name="accept">Accept the terms of this site</button>
</div>

Comments

0

in javascript you need to do this:

  <script>
    var v_accept = document.querySelector("#accept");
    v_accept.addEventListener('click',function(){
       var v_term = document.querySelector("#term");
       v_term.style.display = 'none';
     });
   </script>

Comments

0

Try loading on document.ready:

$document.ready(function(){ 
  $("#accept").click(function(){
    $("#term").hide("fast");
  });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.