Link to home
Start Free TrialLog in
Avatar of AivsCoder
AivsCoder

asked on

Why isn't this css class being added to my footer tag via JQuery.


Here is my HTML5 and PHP
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8"/>
<link rel="stylesheet" href="css/mycss.css"/>
<script src="jquery-1.6.2.min.js"></script>
<script src="myjs.js"></script>
<body>
<?php
	$firstname = "Ben";
	$secondname = "Benn";
	$actualname = "";
	
	const MYNICKNAME = "benny";
	define("MYCONSTANT","Benny Bong");
	if ($firstname === $secondname) { echo "They are the same"; } else { echo "They are different"; }
	 
	echo MYNICKNAME;
	echo MYCONSTANT;
	
	$actualname = (isset($firstname)) ? $firstname : $secondname;
	echo $actualname;
?>
<header class="header">
Ben
<nav></nav>
</header>
	
<aside>
Ben
</aside>
<footer>
Ben
</footer>

</body>
</html>

Open in new window


This is my external css file
 
.header {
	font-style : italic;
}

.boldness{
	font-style : bold;
}

Open in new window


This is my external js file.
$(document).ready(function() 
{
	$('footer').addClass('boldness');
});

Open in new window

Avatar of Hagay Mandel
Hagay Mandel
Flag of Israel image

The JQuery function will be applied to a div with a specific id or class.
You need to creare a div with an id "footer", and then use:
$(document).ready(function() 
{
	$('#footer').addClass('boldness');
});

Open in new window

Pay attention to the '#' symbol.
More on JQuery selectors.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't have a solution to provide, I'm just weak on jQuery and trying to learn, so I'd like to ask @HagayMandel a question. Does jQuery recognize HTML5 tags at all? Because the author's jQuery should work if it did.
jquery recognizes html5 tags. But IE < 9  doesn't.  

I commented out your php - there is an error preventing the page from displaying in IE.

Here is a working file for all browsers but IE < 9:
addClass jquery
Here's the example with the PHP code left in:

addClass jquery (including original PHP)
(could just be the php configuration on my server - but I don't think you're supposed to use const as a global variable)

cheers.
Avatar of AivsCoder
AivsCoder

ASKER

Awesome!!!.