Skip to content

Instantly share code, notes, and snippets.

@ravinsharma12345
Last active December 21, 2015 04:28
Show Gist options
  • Save ravinsharma12345/6249461 to your computer and use it in GitHub Desktop.
Save ravinsharma12345/6249461 to your computer and use it in GitHub Desktop.
I'm trying to get a grab on jQuery. This is to document how it works and some context on using jQuery
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Demo</title>
<! -- javascript allow wizards to manipulate the world of DOM, DOM is a world that can display all sorts of knowledge
and we shall use the power of javascript -->
<!-- javascript has a lot of power, but there a dimensional issue involving browser universe . Each universe has different behaviour to javascript. To resolve this issue, jQuery is an advance universal magic that is founded on javascript used for cross dimensional DOM manipulation. We shall learn jQuery in this bin -->
<head>
<!-- loading jquery from cdn source -->
<script type="text/javscript" src="http://codeorigin.jquery.com/jquery-2.0.3.min.js"> </script>
<!-- lets make sure the html document is loaded before using jQuery -->
<script>
window.onload = function(){ alert("Welcome Asshole"); } //was in a bad mood when writing this
//the thing about the above method is code does not run untill all images are downloaded.
//including banner ads. Lets not wait too long
//use this method instead, methods load when document is ready to be manipulated
$(document).ready(function(){
$("a").click(function(event){ //a click event handler
event.preventDefault(); //prevents the default browser action for click events
alert("Thanks for the visiting!");
}
}
</script>
<script type="text/javscript">
//we had a little fun on playing with jquery click event, now lets manipulate HTML
// lets add an html block element
// jquery allow the magician to add a html element inside an element or outside and element
// we want to add inside a element of body
</script>
</head>
<body>
<!-- html link to jQuery site -->
<p><a href="http://jquery.com" style="text-decoration:none;"></a></p>
</body>
</html>
Basic selectors
---------------
$('a') => all anchor element
$(".foo") => all class with foo
$("#foo") => the id called foo
$("p.hover") => all p elements with class hover
$("p.hover, p#bar") => all p elemnt with class hover, and all p elements with id bar
Hierarchy selectors
$('body span') => all span inside body
$('p>span') => direct span or first child span inside p
$('.fpp+p') => the next element p, after class .fpp
Filters
- Basic filters
- Content filters
- Visibility filters
- Attribute filters
- Child filters
Forms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment