1

Why doesnt this work?

$(".char").click(function() {
   $(this).css('border', "solid 2px red");  
   });

<img class=char src=1.gif>
<img class=char src=2.gif>

I want it to highlight via border when I click one of the images.

Also I'd like only one to be highlighted at once but I guess I'll look at that after.

0

1 Answer 1

3

use $(document).ready() - your current jquery code executes before the targeted html elements are available in the dom

<script type="text/javascript">
$(document).ready(function() {
    $(".char").click(function() {
        $(this).css('border', "solid 2px red");
    });
});
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.