Jump to content

Javascript- Change This To Css

HELP

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Javascript- Change This To Css HELP Rate Topic: -----

#1 User is offline   papina 

  • W.R. Private
  • Group: Members
  • Posts: 1
  • Joined: 22-March 11

Posted 24 March 2011 - 06:47 PM

So i found this code. it changes the color of the h1 tag. I want it to be able to change an element in an external css file? any ideas???

I know its some where in this line... i just dont know what to add?

$('h1').css('color', $(this).css('backgroundColor'));


Please help!


<?php include($DOCUMENT_ROOT . "../includes/menu.php"); ?>

<br/><br/><br/>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<style type="text/css" media="screen">
#header {

background: red;
padding: 2em 1em;

}

#header h1 {
display: inline;
}

#colorsContainer {
float: right;
display: none;

}

#colorsContainer div {
width: 30px;
height: 30px;
float: left;
display: inline;
cursor: pointer;
}
</style>
</head>
<body>
<div id="header">
<h1>My Header</h1>
<div id="colorsContainer"></div>
</div>

<div id="main">
<h2>A Heading Goes Here</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<p>

<h2>A Heading Goes Here</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<p>

<h2>A Heading Goes Here</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<p>
</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">

var colorOptions = 'black, blue, orange, green, purple'.split(', '),
colorDivs = [],
colorsContainer = $('#colorsContainer');

for ( var i = 0, len = colorOptions.length; i < len; i++ ) {
var div = $('<div />').css('background', colorOptions[i])[0];
colorDivs.push(div);
}

colorsContainer.append(colorDivs);

$('#header').hover(function() {
colorsContainer
.fadeIn(200)
.children('div')
.hover(function() {
$('h1').css('color', $(this).css('backgroundColor'));
});
}, function() {
colorsContainer.fadeOut(200);
});

</script>
<h2><a href="assignment8.php"><img src="images/back.png" alt="back"/>Back</a></h2>

</body>
</html>

This post has been edited by papina: 24 March 2011 - 06:48 PM

0

#2 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 26 March 2011 - 12:07 AM

You mean you want to put the js and css in an external file? I'm not clear on what the external file part is that you're asking.
0

#3 User is offline   EncoderDecoder 

  • W.R. Sergeant
  • Group: Members
  • Posts: 260
  • Joined: 01-March 11
  • Gender:Female
  • Location:Philippines

Posted 21 May 2011 - 11:05 AM

external css file..? but you are using an internal css..

:confused:

:confused1:
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users