SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery Selector Troubles

    Hi. This has to be a simple oversight on my part, but for the life of me I can't figure it out. Consider the following (simplified) HTML:

    HTML Code:
    <div id="chalk">
    <a name="bk_99"></a>
    <div class="chalk_entry">
      <div class="chalk_message">...</div>
      <div class="chalk_block">
        <div id="msg_114" class="inner_chalk_entry">
          <div class="inner_chalk_message">...</div>
        </div>
        <div id="msg_115" class="inner_chalk_entry">
          <div class="inner_chalk_message">...</div>
        </div>
      </div>
    </div>
    <a name="bk_72"></a>
    <div class="chalk_entry">
      <div class="chalk_message">...</div>
      <div class="chalk_block">
        <div id="msg_73" class="inner_chalk_entry">
          <div class="inner_chalk_message">...</div>
        </div>
      </div>
    </div>
    </div>
    For the sake of simplicity, let's say that I want to change the color of the text within the DIVs with the IDs msg_115 and msg_73 (the last ones in each "block"). Here is the Javascript I'm attempting to do this with:

    Code:
    $('#chalk>a').each(function(){
        var lastId=$(this).next('.chalk_entry .chalk_block .inner_chalk_entry:last').attr('id');
        $('#' + lastId).css('color','green');
    });
    When this runs, it only changes the color of the text within the DIV with the id of "msg_73". I assume I'm doing something wrong with the "last" filter, but what? Any help would be greatly appreciated.

  2. #2
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, it appears that what I want is :last-child and not :last.


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
  •