English 中文(简体)
子女
原标题:JQuery: find parent and another child
  • 时间:2012-05-15 09:33:15
  •  标签:
  • jquery

I have the following markup:

<div style="width: 660px; border-bottom: 1px solid #3A3F46;">
            <div class="noplace_event_cont">
                <div style="float: left;">
                    <span class="title">Usual</span> 
                    <span class="desc">Free: <span class="free_place">19</span></span>
                </div>
                <div style="float: right;">
                    <div class="spinner_cont">
                        <input type="text" data-type="1" class="event_spinner" value="0" maxlength="1" style="width: 24px; margin-right: 16px; text-align: right;"><span class="ui-spinner ui-widget"><div class="ui-spinner-buttons" style="height: 41px; left: -16px; top: -13.0833px; width: 36px;"><div class="ui-spinner-up ui-spinner-button ui-state-default ui-corner-tr" style="width: 16px; height: 20.5px;"><span class="ui-icon ui-icon-triangle-1-n" style="margin-left: 16.5px; margin-top: 15px;">&nbsp;</span></div><div class="ui-spinner-down ui-spinner-button ui-state-default ui-corner-br" style="width: 16px; height: 20.5px;"><span class="ui-icon ui-icon-triangle-1-s" style="margin-left: 16.5px; margin-top: 15px;">&nbsp;</span></div></div></span>
                    </div>
                </div>

            </div>
            <div class="noplace_event_cont">
                <div style="float: left;">
                    <span class="title">VIP</span> 
                    <span class="desc">Free: <span class="free_place">6</span></span>
                </div>
                <div style="float: right;">
                    <div class="spinner_cont">
                        <input type="text" data-type="2" class="event_spinner" value="0" maxlength="1" style="width: 24px; margin-right: 16px; text-align: right;"><span class="ui-spinner ui-widget"><div class="ui-spinner-buttons" style="height: 41px; left: -16px; top: -13.0833px; width: 36px;"><div class="ui-spinner-up ui-spinner-button ui-state-default ui-corner-tr" style="width: 16px; height: 20.5px;"><span class="ui-icon ui-icon-triangle-1-n" style="margin-left: 16.5px; margin-top: 15px;">&nbsp;</span></div><div class="ui-spinner-down ui-spinner-button ui-state-default ui-corner-br" style="width: 16px; height: 20.5px;"><span class="ui-icon ui-icon-triangle-1-s" style="margin-left: 16.5px; margin-top: 15px;">&nbsp;</span></div></div></span>
                    </div>
                </div>

            </div>
    </div>

我想在<代码>span上找到案文,free_place。 班级:

$(".event_spinner").each(function () {
            var max = $(this).parent(".noplace_event_cont").find(".free_place").text();
            alert(max);
        });

But, this code not working. max is undefined.
Thanks.

最佳回答
var max = $(this).closest(".noplace_event_cont").find(".free_place").text();

var max = $(this).closest(".free_place").text();
问题回答

我想找到一段文字,可以自由选择:

$( span .free_place ).text()

或者:

$( span.free_place ).text()

很难理解你想要产出是什么。

    $(".event_spinner").each(function () {
        var max = $(this).parents(".noplace_event_cont").find(".free_place").text();
        alert(max);
    });

使用<代码>。

rel=“nofollow”>demo jsFiddle

$(".event_spinner").each(function () {
            var max = $(this).closest(".noplace_event_cont").find(".free_place").text();
            alert(max);
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签