Jump to content
george

jQuery CSS function not working

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

Share this post


Link to post
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

Share this post


Link to post
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>

Share this post


Link to post
Share on other sites

Problem fixed, as I did change it to

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

and that did correct my problem.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...