#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Wink Create a JavaScript selection


    Hi everyone!,
    I'm learning javascript, that is why need your help.
    I have this template
    <javascript>
    var $ = function (selector) {
    var elements = [];

    return elements;
    }
    </javascript>
    in elements i have to return array that contenst the selector with the value, and when call $("div") - Should return 2 DIVs
    any idea how to do it? thanks to all in advance.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    there is no "javascript" element in HTML. I guess you meant
    Code:
    <script type="text/javascript"></script>
    Also, what exactly is the point of your script? Reinventing jQuery?
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    Hi, I think I didn't explain very well.
    I have 3 files
    Test.html contains the HTML function will be tested
    <!DOCTYPE html>
    <head>
    <script src="Answer.js"></script>
    <script src="Test.js"></script>
    </head>
    <body>
    <div></div>
    <div id="some_id" class="some_class some_other_class"></div>
    <img id="some_other_id" class="some_class some_other_class"></img>
    <input type="text">
    </body>
    Test.js contains a function which provide results for your answer in the developer console
    Answer.js contains a template function that should return an array of DOM elements that match the CSS selector.

    var $ = function (selector) {
    var elements = [];

    return elements;
    }
    I hope I give more idea, what I want to do. thanks!
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    I understand what you're trying to do. The question is why you want to do it, because you're reinventing the wheel. Every framework on this planet (jQuery, Prototype, YUI, ...) has those element selectors already. So unless you do this purely for learning, it's pretty pointless.

    Anyway, selecting all elements of the same type is a native JavaScript method:
    getElementsByTagName
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    yes, you right. But I'm learning that is why. Anyway thanks for try to understand me

IMN logo majestic logo threadwatch logo seochat tools logo