SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't get jQuery .prev to match my criteria

    I'm looping through each counter on my page to modify those sections. When I try to use the syntax recommend in the jQuery API, however, I can't specify the prev function to match only certain criteria. I've tried...

    .prev(":radio")
    .prev("input[name='technology1']")

    However, the only thing I can get to work is...

    var test = thisCounter.prev().prev();

    that works now but it's pretty fragile given that the designers are likely to rework these sections from time to time. How can I grab the previous element which MATCHES my criteria?
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Show us the HTML?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Done.
    <ul id="list1">
    <li>
    <input name="software1" id="avc" type="radio" value="" />
    <label> AVC</label>(<span class="counter">3</span>)
    </li>
    <li>
    <input name="software1" id="bcl_converter" type="radio" value="" />
    <label> BCL Converter</label>(<span class="counter">26</span>)
    </li>
    .
    .
    .
    </ul>

    <ul id="list2">...</ul>
    <ul id="list3">...</ul>
    <ul id="list4">...</ul>

    I'm iterating over all .counter items with an .each() and I'm trying to grab the sibling radio button. I sounds like you can pass a selector into prev(), but I haven't been able to get that to work and don't understand why. I guess .prev().prev() is OK, but it seems klunky to me.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Try using prevAll('input') instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •