Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery Selector for input value

i have here the code..

 <div>     <input type="hidden" value="hello" />  </div>   <div>     <input type="hidden" value="world" />  </div> 

is it possible to select the div with the value "hello" inside and change the selected div's color to red...?

 $("div input[value='hello']").css("background","red"); //i have this in mind                                                         //but i think its wrong:D 

any help please..

like image 846
Vincent Dagpin Avatar asked Feb 20 '11 22:02

Vincent Dagpin


People also ask

How do I set the value of a element in jQuery?

jQuery val() Method The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element.

What does VAL () do in jQuery?

val() method is primarily used to get the values of form elements such as input , select and textarea . When called on an empty collection, it returns undefined . When the first element in the collection is a select-multiple (i.e., a select element with the multiple attribute set), .

What is $() in jQuery?

$() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements. Most of the time you will need to start with $() function. It is advisable to use jQuery after DOM is loaded fully.


1 Answers

You want to select the input, then take its parent div:

$("input[value='hello']").parent("div").css("background", "red"); 
like image 168
BoltClock Avatar answered Oct 16 '22 19:10

BoltClock