Richardlonesteen
Richardlonesteen

Reputation: 594

setting style with jquery to paragraphs in a div

its a very simple setup with some css and a line of javascript to make some changes:

#pass p {
    overflow: hidden;
    width: inherit;
}
<div id="pass">
    <p></p>
    <p></p>
</div>
$("#pass > p").setStyle({backgroundColor:$('colorpicker3').style.backgroundColor});

does anyone know how to set style to all of the paragraphs with jquery ? Thank you

Upvotes: 0

Views: 49

Answers (2)

Danny P
Danny P

Reputation: 83

To add to the other answers, you can add multiple css rules to a target by using

$(".targetClass > p").css({ "background-color":"red", "color": "#fff" });

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337560

You should use the css() method to set the style of an element in jQuery:

$("#pass p").css('background-color', $('colorpicker3').css('backgroundColor'));

Note however, that it's better practice to set your styles in your CSS and use addClass to set it on the required elements. Also, the $('colorpicker3') selector is not correct. Assuming it's a class you need to precede it with a ., or if it's an id it needs #.

Upvotes: 1

Related Questions