Jump to content

jQuery CSS function not working


george
 Share

Recommended Posts

I have a very simple jQuery line of code that is not working.

$("p#t1").css("color","#ffffff");

In my document I have a P tag with an ID of t1.

 

I have attached my entire HTML file should this be helpful.

 

TIA

 

My ID of t1 is not declared in my CSS. Could this be the problem?

 

I am going to declare it now.

triangle.html

Edited by george
Link to comment
Share on other sites

You can't nest block pre element within paragraph, what is happening is a closing paragraph is created immediately following the opening tag, and vice versa with closing paragraph tag creating empty paragraphs. So no text, and nothing to apply color.

 

EDIT: Oh yea, change to block element like div

Edited by dsonesuk
Link to comment
Share on other sites

Wrong syntax $("p#t1").css({"color": "#ffffff"}); but still won't work! as already said browser renders

 <p id="t1"><pre>.t1 {    border-color: blue red green yellow;    border-style:solid;}                </pre>           </p>

AS

 <p id="t1"></p><pre>.t1 {    border-color: blue red green yellow;    border-style:solid;}                </pre>           <p> </p>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...