Jquery each with selectors

I'm new at jquery. Once used mootools and infact prototype. I start using this pack because drupal uses.
I start writing code by my way. I got elements selecting $("#myDiv div") and tried to convert all of themat once. In jquery docs like php correspondance foreach I found each function.

$("#myDiv div").each(
function (index, foo){
//do someting with foo
}
)

But weired thing happened, my code didnt work! The perfect explanation should be

each provides, when selecting elements, elements it self. Its prototype is not touched by jquery. If you want jquery extensions work, you should use $(foo).

After a while I found there is no need for index or elem. Using this gives the same result. Perfect implication is:


$("#myDiv div").each(
function (){
$(this).width(this.childNodes.length*500 + 'px');
}
);

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
                           .d8888b.    .d888  888                
d88P Y88b d88P" 888
888 888 888 888
88888b.d88b. 88888b. Y88b. d888 888888 88888b. 88888888
888 "888 "88b 888 "88b "Y888P888 888 888 "88b d88P
888 888 888 888 888 888 888 888 888 d88P
888 888 888 888 d88P Y88b d88P 888 888 d88P d88P
888 888 888 88888P" "Y8888P" 888 88888P" 88888888
888
888
888
Enter the code depicted in ASCII art style.

Similar

  • New technique to win olimpics -

    New technique to win olimpics

    At the 1968 Olympics, Dick Fosbury took the athletics world by surprise with an unusual high-jump technique.

  • Printing mysql_error -

    Printing mysql_error

    This is a code snipped to print mysql error.
    If there is no error mysql_error returns null, thus if evaluates false and there is no output.

  • multiple ON DUPLICATE KEY UPDATE -

    multiple ON DUPLICATE KEY UPDATE

    Here is an example of how to update multiple columns using values supplied in the INSERT statement. This assumes that column 'a' is the unique key.

  • multiple ON DUPLICATE KEY UPDATE -

    multiple ON DUPLICATE KEY UPDATE

    Here is an example of how to update multiple columns using values supplied in the INSERT statement. This assumes that column 'a' is the unique key.

  • php unlink recursive -

    php unlink recursive

    The shortest recursive delete possible.

    <?php
    /**
    * Delete a file or recursively delete a directory
    *
    * @param string $str Path to file or directory
    */