开发者

Filter not functioning, need only the tags whose child match a selector

开发者 https://www.devze.com 2022-12-27 07:58 出处:网络
given the html: <div class=\"ships\"> <div class=\"ship header\"> </div> <div class=\"ship\">

given the html:

<div class="ships">
  <div class="ship header">
  </div>
  <div class="ship">
    <div class="image">
      <img alt="Hermes_class" src="..." />
    </div>
    <div class="number">x10</div>
  </div>
 ... //other ships

I want only the number text of the ship matching img alt="Hermes_class".

Here's where I start:

var finalShipListDom = $jq('div开发者_开发问答.ship:not(.header)', finalCombatantShips);
             if(finalShipListDom.length<=0)
                 console.log("fsld="+finalShipListDom.length);

i've tried all these to get the ship dom so I could go down from there to get the number.

$jq('div.ship',finalShipListDom).filter('div.image img[alt="' +shipClass + '"]');

and

 var finalShipDomFilter= function(index){
               return jQuery('div.image',this).length>=1;
             }

and

     var finalShipDomFilter= function(index){
               return jQuery('div div.image',this).length>=1;
             }

all are returning 0 length.

There's a debug bin/live example available at http://jsbin.com/alebi3/9/edit


It sounds like you want jQuery.has(). Something like this should get you the div that contains the div <div class="number">x10</div>:

$jq('div.ship:not(.header)', finalCombatantShips)
    .has('div.number > img[alt=' + shipClass + ']');

N.B. you do not need to insert quotes into the attribute value in the selector.

0

精彩评论

暂无评论...
验证码 换一张
取 消