SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem of symbol

    $('[name^=strCustTerr]')

    what does this ^= means ? I don't think its "not"..what is it ?


    if(strCustTerr.size() === strCustTerr.filter(':checked').size()){

    what is this symbol : ..what it means when we do :checked ?

  2. #2
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Forgot to mention that those are JQuery syntax.

  3. #3
    Learning... tahirjadoon's Avatar
    Join Date
    Jan 2003
    Posts
    775
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This page details all the selectors and there use:
    Selects elements that have the specified attribute with a value beginning exactly with a given string.

    This selector can be useful for identifying elements in pages produced by server-side frameworks that produce HTML with systematic element IDs. However it will be slower than using a class selector so leverage classes, if you can, to group like elements.
    I have tried testing ^= with the following code, click event only got applied to chk1 as that is the exact match:

    html
    Code:
    <input type="checkbox" name="chk1" value="1">1<br>
    <input type="checkbox" name="chk2" value="2">2
    jquery
    Code:
    $(document).ready(function(){
    
            $('input[name ^= "chk1"]').click(function(){
                alert($(this).val());
            });
        });
    Any thing that starts with a : is a selector, these are used for "matching a set of elements in a document".

    In the example below, click only gets attached to chk2.

    html
    Code:
    <input type="checkbox" name="chk1" value="1" checked>1<br>
    <input type="checkbox" name="chk2" value="2">2
    jquery
    Code:
    $(document).ready(function(){
    
            $('input:not(:checked)').click(function(){
                alert($(this).val());
                
            });
        });
    Take a look at the following page, it has detailed information.
    http://api.jquery.com/category/selectors/

    I have modified the above code and used :not and :checked inside the if statement. It always alerts 'checked' even when the check box is not checked. .attr('checked') on the other hand behaves properly. A jQuery guru will need to explain this behavior.

    Code:
    $(document).ready(function(){
    
            $('input[type="checkbox"]').click(function(){
                
                //*** this always results in checked
                if($(this)+(':not(:checked)'))
                    alert('checked');
    
                else
                    alert('not checked');
                
                //*** this outputs properly
                if($(this).attr('checked'))
                    alert('checked');
    
                else
                    alert('not checked');
                
            });
        });
    The beauty of life is not dependent on how happy you are,
    but on how happy others can be because of you...

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Those are standard CSS syntax.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •