www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] jquery to addclass to nth-child

  1. #1
    Join Date
    Jun 2006
    Location
    Boston, MA
    Posts
    383

    resolved [RESOLVED] jquery to addclass to nth-child

    i'm having some trouble with these lines here. im not sure why they aren't working for me.

    i've tried each of these lines, separately obviously. its supposed to select every 5th child of the #tin-ebay-results div but it doesn't seem to want to! thoughts?

    HTML Code:
    <script>$('#tin-ebay-results > div:nth-child(5n+1)').append('class="noRightMarg"');</script>
    <script>$('#tin-ebay-results div:nth-child(5n+1)').append('class="noRightMarg"');</script>
    <script>$('#tin-ebay-results :nth-child(5n+1)').append('class="noRightMarg"');</script>
    <script>$('#tin-ebay-results:nth-child(5n+1)').append('class="noRightMarg"');</script>
    <script>$('#tin-ebay-results #child-div:nth-child(5n+1)').append('class="noRightMarg"');</script>
    and the same iterations using the addclass function below
    HTML Code:
    <script>$('#tin-ebay-results > div:nth-child(5n+1)').addClass('noRightMarg');</script>
    Last edited by absolutmgd13; 05-22-2012 at 01:40 PM.

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    The append function will not add the class="..." to the element's attributes.
    Can you paste some of the HTML (not just javascript) showing the target elements?

  3. #3
    Join Date
    Jun 2006
    Location
    Boston, MA
    Posts
    383
    Quote Originally Posted by holyhttp View Post
    The append function will not add the class="..." to the element's attributes.
    Can you paste some of the HTML (not just javascript) showing the target elements?

    heres the jist...

    HTML Code:
    <html>
    <head>
    <style>
    #prod-wrap{float:left;width:200px;height:200px;margin:0 15px 15px 15x}
    .noRightMarg{margin-right:0 !important;}
    </style>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script>$('#tin-ebay-results div:nth-child(5n+1)').addClass('noRightMarg');</script>
    </head>
    <body>
    <div id="tin-ebay-results">
    	<div id="prod-wrap" class=""></div>
    	<div id="prod-wrap" class=""></div>
    	<div id="prod-wrap" class=""></div>
    	<div id="prod-wrap" class=""></div>
    	<div id="prod-wrap" class=""></div>
    	<div id="prod-wrap" class=""></div>
    	<div id="prod-wrap" class=""></div>
    	<div id="prod-wrap" class=""></div>
    	<div id="prod-wrap" class=""></div>
    	<div id="prod-wrap" class=""></div>
    </div>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles