Reputation: 57
can anyone give me an idea why this code wouldn't work
<script>
$(document).ready(function(){
$(".colorDiv").mouseover(function(){
$(this).attr(border, "2px");
$(this).attr(border-style, "solid");
$(this).attr(border-color, "#2F4F4F");
});
});
I'm trying to get a div to have a highlighted border on hover, this is my first experience of jquery and am not sure what I'm doing wrong. the debug says invalid argument, I am a bit unsure how the this parameter works.
any advise would be great.
Upvotes: 0
Views: 27
Reputation: 318182
hyphens are invalid here
$(this).attr(border-style, "solid");
unless it's quoted
$(this).attr('border-style', "solid");
same goes for the color, and you could also camelCase it if you use a object.
$(this).attr({borderColor : "#2F4F4F"});
also, you're setting styles
$(".colorDiv").mouseover(function(){
$(this).css("border", "2px");
$(this).css("border-style", "solid");
$(this).css("border-color", "#2F4F4F");
});
as a sidenote, everything is chainable in jQuery, and many methods accept objects, and CSS has shorthands, which jQuery will accept
$(".colorDiv").mouseover(function(){
$(this).css("border", "2px solid #2F4F4F");
});
Upvotes: 3