Click here to Skip to main content
15,891,903 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:

Content of page 1

Content of page 2

Content of page 3



What I have tried:

check= function(){
$("#step_wrapper > div").css("background-color":"red");
}



it is changing background color of all step_box1 ,I want to change background-color of selected div only.
thank you
Posted
Updated 17-Jan-18 5:45am
v3
Comments
Sergey Alexandrovich Kryukov 25-May-16 22:47pm    
In the context of this question, there is only one meaning of the expression "selected": set of DOM objects (or rather jQuery wrappers) returned by jQuery selector expression.

Obviously, you mean something different, perhaps something which does not exist. If you meant what is selected by the selectors (in your case, old div elements which are children of the element with id="step_wrapper"), what you get would be what you expected, by definition. I don't understand why would you expect something else (you say, "all step_box1", but its not clear what it is).

It's quite possible that what you call "selected div only" simply does not exist. If you simulate UI concept of selection (such as selected menu item, which is not a predefined HTML concept, unlike, say, selected list element), you have to explain how you do it. In other words, define what is "selection" and you will get the solution. And if there is a strict criteria of "selection", the solution will be quite simple.

—SA

try this

$(function() { $( "#step_wrapper > div" ).click(function() { 
$( "#step_wrapper > div" ).removeClass('active');
   $(this).addClass('active');
 });
});


in css
.active{background-color:red;}
 
Share this answer
 
As your code is unclear it looks like problem with selector you are using for "div" elements. You have to use proper selector and make sure that element is exist. Otherwise
JavaScript
.css("background-color":"red")
will apply to all "div" inside "#step_wrapper" or to nothing.

Add more detail to your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900