Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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="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>
like image 698
user610983 Avatar asked Aug 25 '11 08:08

user610983


People also ask

How to get all elements of a specific class inside div?

In this article, we will find how to get all elements of a specific class inside an HTML div tag. To do this we will use HTML DOM querySelectorAll () method. This method of HTML DOM (document object model) returns all elements in the document that matches a specified CSS selector (s). The syntax to use this method is as follows.

How do I select a button element in HTML?

The :button selector selects button elements, and input elements with type=button. Tip: Using input:button as a selector will not select the button element.

How to select only div elements that have class attribute MyClass?

For instanse you can do The last one will match every myclass inside myDiv, including myclass inside myclass. If you want to select every element that has class attribute "myclass" use If you want to select only div elements that has class attribute "myclass" use try this instead $ (".video-divs.focused").

What does <input type=button> mean in HTML?

The <input type="button"> defines a clickable button (mostly used with a JavaScript to activate a script). The numbers in the table specify the first browser version that fully supports the element.


Video Answer


2 Answers

I think the answer is:

$("div.blueheaderbar.selected").find("input").val("hide it");
like image 80
shernshiou Avatar answered Nov 15 '22 01:11

shernshiou


"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");
like image 31
RoToRa Avatar answered Nov 15 '22 01:11

RoToRa