开发者

How to get this parent value?

I'm trying to get a value thanks to parents method of jQuery, but I can't find the good "way".

Can you help me please ?

The even开发者_如何学Got is on the click of .user-create class, and the value to get is "09h00"

Now, I do it: myVar = $(this).closest('div').prevAll(':last').children('.heure').text(); but it doesn't work

<li>
   <div class="docheure">
      <span class="heure">
         09h00 <!--IT'S THE VALUE I NEED -->
      </span>
      <span class="doc">
         Dr.Grey
      </span>
   </div>
   <div class="detailrdv">
      <p><span>M / Mme</span> : blabla | <span>Phone</span>: 00000</p>
      <p><span>Examen</span> : crane | <span>Secrétaire</span> : M.J</p>
      <p><span>Remarque :</span></p>
      <p>
      </p>
   </div>
   <div class="contenercommandes">
      <div style="display: none;" class="commandes">
         <ul>
            <li>
               <!--THIS IS THE LINK EVENT-->
               <a href="#" class="editer">
                  <img src="btn_edit.png" alt="editer">
               </a>
            </li>
         </ul>
      </div>
   </div>

</li>


I believe that this should work:

myVar = $(this).closest('li:has("div.docheure")').find('.heure').text();

Edited in response to @lonesomeday's accurate comment. (I missed the nested ul/li)


How about this?

$(this)
 .closest('div.contenercommandes')
 .siblings('div.docheure')
 .find('span.heure')
 .text();

Working jsFiddle.


$(this).closest('div').prevAll(':last').children('.heure').text();

instead you must use, html(). Like:

$('.docheure .heure').html()


Try this:

$("a.editer").click(function () {
    var myVal = $(this)
        .closest('.contenercommandes')
        .prevAll('.docheure')
        .children('.heure')
        .text()
    ;
});


Is this the kind of thing you were after? http://jsfiddle.net/thewebdes/ZQasw/

$('.user-create').click(function(){
  alert($('span.heure').html());
});


If I understand your question correctly, this should help.

myVar = $(this).closest('div.docheure').find('.heure').text();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜