A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Do I have a syntax error?

983 views · started by HTML ·
#1
Do I have a syntax error?
been messing around with Jquery, wondering if I have an error with this small peice of code, maybe the css function?
	$('#wrap').mouseover(function (){
$(this).css({
'background-color':'#FFFFFF',
'filter':'alpha(opacity=100)',
'opacity ':'1.0'
});
});


here's what it looks like in plain JS that works.
function mouseOver(){
var oWrap = document.getElementById('wrap');
oWrap.style.backgroundColor = "#FFFFFF";
oWrap.style.filter = "alpha(opacity=100)";
oWrap.style.opacity = 1.0;
}
#2
The jQuery itself is fine. Just a couple of things to watch out for:

1. You can only execute most jQuery code after the DOM has fully loaded. Almost all of your code should go in:

$(document).ready(function() {
// code here
});


2. If you're using any other Javascript libraries, they may have taken control of the $ keyword. If that's the case, use jQuery instead of $ (i.e. jQuery(document).ready(function() { )
#3
Yeah, I have it in the ready, that's a given. Though it's still not working correctly. I'll look more into later, I'm too excited to care anymore.

I will never go back to traditonal JS after learning this, I've turned a highlighting function into something as small as this! I'll continue looking over Jquery and hopefully, I can release something.


$(document).ready(function() {
$('#blue').hover(function() {
$(this).toggleClass("highlight");
});
});
#4
That snippet of Javascript is fine. I just tested it.

If it still isn't working, I'd wager there's some invalid syntax elsewhere that's causing it all to break. Might be easier if you pasted/PMed me the entire page's source code.

And yes, jQuery is great :)