How To Add CSS Class To My Images......

Discussion in 'jQuery' started by strgraphics, Jan 16, 2012.

  1. #1
    <html>
    <head>
    <script type="text/javascript" src="jquery.js"></script>

    <script type="text/javascript">
    $(document).ready(function(){
    $("[img='.jpg']").addClass("intro");
    });
    </script>

    <style>
    .intro
    {
    border: 10px solid #000000;
    }
    </style>

    </head>
    <body>
    <img src="1.jpg"></a><br>
    <img src="2.jpg">
    </body>
    </html>






    But its not working, pls help me...???
     
    Solved! View solution.
    strgraphics, Jan 16, 2012 IP
  2. #2
    1) wrap code inside of the code tags
    2) that is because your selector is completely wrong. You should read more about jQuery selectors here: http://api.jquery.com/category/selectors/
    3) proper selector below

    
    $("img").addClass("intro");
    
    // If you wanted to do it with just those that end in .jpg
    $("img[src$='.jpg']").addClass("intro");
    
    Code (markup):
     
    JamesD31, Jan 17, 2012 IP
  3. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Hi James, Its working thanks lotttt.
    Am fresher, really thanks for for your help.
     
    strgraphics, Jan 17, 2012 IP
  4. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4

    Hi friend....
    $("img[src$='.jpg']").addClass("intro"); is not working... can you pls check one...
    even i tryed
    $("[src$='.jpg']").addClass("intro"); but no luck
     
    strgraphics, Feb 13, 2012 IP
  5. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #5
    James3D1, thank from me also.
     
    Andre91, Feb 13, 2012 IP