introduction to jquery basic selectors

12:02 PM

(0) Comments

hi guys we will talk to day about my favourite javascript framework ( jquery )
and the first lesson you should learn in jquery is Selectors or how you can select a DOM element in the page
ok lets start
first to select a DOM you must wait the full page to load, the javascript programmers know that if we want to control an element in the web page we use
window.onload event to run the code in it
but the problem is that this event will fire after all page downloaded including images and other heavy element
jquery has a similar event but the event fired when the DOM is ready

$('document').ready(function(){
// your code here
});







ok now we know when we will run our code and how and where we write :)
now the good part of our articles : selectors
if you know css you will use selectors perfectly because simply
jquery selectors = CSS
yea its a true, don’t believe me look at the next example

//jquery code
$('document').ready(function(){
$('div.mydiv').hide('slow');
});


/* css code */
div.mydiv{
display:none;
}

do you believe me now try to pick a different between the jquery selector and css selector :) no different
so if you want to select a element with id simple_id
simply type
$(‘#simple_id’)
global elements
for example
$(‘a’)
class
$(‘.simple_class’)
just know css selectors and use it with jquery
the next post in jquery i will discuss the advanced selectors with jquery & css 3 , so keep watching me :)

0 Responses to "introduction to jquery basic selectors"

Post a Comment