PrestonDocks
PrestonDocks

Reputation: 5428

JQuery - How to add background color to div where parent div has ID

Can anyone tell me how I would make the Div that contains "G" below have a Green background color using JQuery. I have used Drupal to provide a class name of bsc-data and an id of t-impact to the parent div.

There will be other div's on the page that also have the class of pane-content but their parent div will have a different id.

<div class="panel-pane pane-token pane-node-field-impact-to-customer bsc-data" id="t-impact">

  <h2 class="pane-title"> </h2>
  <div class="pane-content">G</div>

</div>

Upvotes: 0

Views: 87

Answers (4)

xhg
xhg

Reputation: 1885

$("#t-impact > div.pane-content").css("background-color", "green");

You can see about the css selector. ">" means directly under the parent. So it can select the div.pane-content directly under the #t-impact even if you have another div.pane-content as a child of div.pane-content.

Upvotes: 0

Marikkani Chelladurai
Marikkani Chelladurai

Reputation: 1430

$('#t-impact div').css('background-color',"green")

will do the magic....

Upvotes: 1

Robin
Robin

Reputation: 864

you can use jQuery("#t-impact div).css({background-color:"#00ff00"}); This will apply green back ground to the child div

Upvotes: 0

MrCode
MrCode

Reputation: 64526

This will set the background of the div that is a direct child of #t-impact and has the pane-content class.

$('#t-impact > div.pane-content').css('background-color', 'green');

Docs for .css().

Upvotes: 4

Related Questions