开发者

Find input button within a selected class div

How could I use jquery to find out this button within a div with class name "blueheaderbar accordionButton on" then change button value to "hide it"

<div class="blueheaderbar accordionButton selected" style="margin-top:20px">
            <div class="floatleft">abc</div>
            <div class="floatright"><input class="showhidebtn" type="button" value="Show Outlet" style="margin:6px 16px 0 0; width:86px" /></div>
            <div class="clear"></div>
</div>

<div class="blueheaderbar accordionButton" style="mar开发者_如何学运维gin-top:20px">
            <div class="floatleft">abc</div>
            <div class="floatright"><input class="showhidebtn" type="button" value="Show Outlet" style="margin:6px 16px 0 0; width:86px" /></div>
            <div class="clear"></div>
</div>


I think the answer is:

$("div.blueheaderbar.selected").find("input").val("hide it");


"blueheaderbar accordionButton selected" isn't "a" single class name, but three. The CSS selector to select an element with all three classes is

.blueheaderbar.accordionButton.selected

(notice the lack of spaces!).

So to find an input inside there with jQuery is:

var $input = jQuery(".blueheaderbar.accordionButton.selected input");

or

var $input = jQuery(".blueheaderbar.accordionButton.selected").find("input");


this will do the trick-

jQuery(".blueheaderbar.accordionButton.selected").find(".showhidebtn").hide();

and for secon div try this-

jQuery(".blueheaderbar.accordionButton").find(".showhidebtn").hide();

you can try in this way also-

jQuery(".blueheaderbar.accordionButton.selected > .showhidebtn").hide();

Working Demo


This should change the text

$('.showhidebtn').click(function() {
  $(this).val('hide it');
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜