Find input button within a selected class div
Asked Answered
H

4

11

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="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>
Himelman answered 25/8, 2011 at 8:24 Comment(0)
F
17

I think the answer is:

$("div.blueheaderbar.selected").find("input").val("hide it");
Forecastle answered 25/8, 2011 at 8:30 Comment(0)
T
2

"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");
Tryout answered 25/8, 2011 at 8:28 Comment(0)
N
2

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

Naples answered 25/8, 2011 at 8:31 Comment(0)
B
1

This should change the text

$('.showhidebtn').click(function() {
  $(this).val('hide it');
});
Bamford answered 25/8, 2011 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.