Top Web2

Javascript , CSS , XHTML , Web 2 ,PHP and more

Subscribe to Top Web2

jquery – basic selectors

Posted by Net Code On March - 4 - 2009

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 :)

About the Author

One Response to “jquery – basic selectors”

  1. Ghonim says:

    Nice work Islam
    Allah pleasing u

Leave a Reply

About Us

Hi, welcome to web2 blog . here you will find useful information about web2 , xhtml , css , css3 , html5 , javascript , jquery and much more. Explore the site and enjoy your stay and remember to comeback with your friends.

Flickr

flickrRSS probably needs to be setup