PDA

View Full Version : what's wrong with this?


AFemaleProdigy
08-22-2009, 02:14 AM
Hey everyone! I unfortunately have to work with someone else's coding on this new project. I get a parse error every time I try to put this into my headinclude. I don't know this type of code. Can anyone tell me what is wrong with it?

Thanks!

<script type="text/javascript">
$(document).ready(function(){
$('#mainMenu > li').hover( function() { $(this).addClass('hover') }, function() {$(this).removeClass('hover')});
});
</script>

Dismounted
08-22-2009, 05:24 AM
Parse error when you try to save the template from vBulletin? Could you post the full error?

AFemaleProdigy
08-22-2009, 11:26 AM
Sure. It gives me this error....

The following error occurred when attempting to evaluate the template 'headinclude':

Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in /var/www/vhosts/am-tech.org/httpdocs/community/includes/adminfunctions_template.php(3939) : eval()'d code on line 56

This is likely caused by a malformed conditional statement.

Dismounted
08-22-2009, 11:46 AM
Ah, yes, I see the the error now. The vBulletin template parser is interpreting "$(this)" (+ others) as a PHP variable, which it is not. (The error is thrown because it contains characters that are deemed invalid in a PHP variable.) Try this instead:
<script type="text/javascript">
\$(document).ready(function(){
\$('#mainMenu > li').hover( function() { \$(this).addClass('hover') }, function() {\$(this).removeClass('hover')});
});
</script>

AFemaleProdigy
08-22-2009, 12:01 PM
Yeay!! That worked! Thanks so much! :D