views:

881

answers:

2

I have this code:

$("div[id^='intCell']").mouseover(function() {
 $(this).css({ "border:","1px solid #ff097c"});
}).mouseout(function() {
 $(this).css({"border:","1px solid #000"});
})

But I can't get it to work! In the html there is a list of divs which are generated by php to have ids of intCell_1, intCell_2 etc. Any ideas?

+1  A: 

UPDATED:

you can use the command "hover" in place of "mouseover" and mouseout", and use the asterisk in the attribute selector:

example:

$("div[id*='intCell']").hover(function() {
 $(this).css({border:"1px solid #ff097c"});
},
function() {
 $(this).css({border:"1px solid #000000"});
});
Marwan Aouida
+2  A: 

Your CSS object literal syntax is incorrect!

It should be:

$("div[id^='intCell']").mouseover(function() {
        $(this).css({ "border": "1px solid #ff097c"}); // <-- This syntax was wrong
}).mouseout(function() {
        $(this).css({"border": "1px solid #000"}); // <-- This syntax was wrong
})

Working sample: http://jsbin.com/iyoba (Editable via http://jsbin.com/iyoba/edit)

brianpeiris
thanks brianpeiris, I've copied the code from the example you set up exactly but it's still not working for me. The only other thing I can think of is that the divs are generated by a php script that I include in the page via a require_once command. Could that effect anything?
musoNic80
It shouldn't affect it. As long as the divs are in the source once the browser receives it, it should work.Make sure you are placing the code inside a "document ready" wrapper like this: $(document).ready(function(){/*your code should go here*/})If you could show us some of your HTML source code, it would be easier to help you. (Perhaps you could recreate the problem on jsbin.com and then share the public URL with us)
brianpeiris
http://jsbin.com/uzawo
musoNic80
Thanks for recreating the problem. The code in the sample you linked to has an HTML syntax error. The script tag containing the jquery code is missing a quote in the type attribute. Correcting that seems to fix the problem.
brianpeiris
Thanks so much! I can't believe it was something that simple! Thanks also for introducing me to jsbin.com - I think that could be a really useful tool. Now to try and write my first ever AJAX request...
musoNic80
You're welcome. Good luck and happy coding!
brianpeiris