Wednesday, 2 January 2013

Get the input by ID

Let's say you have 3 buttons which starts with "f1" and below is the HTML tags:

        <input type="button" id="f1.1" value="test1" />
        <input type="button" id="f1.2" value="test2" />
        <input type="button" id="f1.3" value="test3" />

When you run the following JQuery code, you will get different result:

            var v1 = $('#f1.1');              => this returns zero match.
            var v2 = $('input[id^="f1"]');  => this returns 3 matches.
            var v3 = $('input[id="f1.2"]'); => this returns 1 match (i.e., the second button).

If you are using "#" in the selector, the result is either 0 or 1 (it's always stop after it found the first one).

For more details, check out the following reference:

    http://api.jquery.com/category/selectors/

No comments:

Post a Comment

We are moving

We are moving this blog to our new blog site: https://ciysys.com/blog/nodejs.htm