Skip to content

Instantly share code, notes, and snippets.

@CleliaRezzola
Forked from ohararyan/Quiz.md
Last active August 29, 2015 14:04
Show Gist options
  • Save CleliaRezzola/fc4e4e3afdd18a654346 to your computer and use it in GitHub Desktop.
Save CleliaRezzola/fc4e4e3afdd18a654346 to your computer and use it in GitHub Desktop.

What is $(document).ready(function() {}); ?

Is a way to start up jQuery. Is telling the system to do something when the document is ready.

How do I select the div.box object in jQuery?

$('.box')

<body>
	<main>
		<div class="container">
			<div class="row">
				<div class="box">
					<h1>Hello World</h1>
				</div>
				<a href="#" class="button">Click me</a>
			</div>
		</div>
	</main>
</body>

How would I hide the above box in jQuery?

$(document).ready(function() { $('.box').hide(); });

How do I create a variable in jQuery?

var name = number; var name = "text"; var name = $('p');

Write a simple function to change the font colour of the h1 element when I click the button in the above example.

$(document).ready(function() { $('.button').click(function(){ $('.box h1') CHANGE FONT COLOR }); });

Write another example to show and hide the box after 1 second when you click the button

$(document).ready(function() { $('.button').click(function(){ $('.box').show (); });

setTimeout(function (){
	$('.box').hide ();
},1000);

});

Run your examples Make sure they work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment