Reputation: 153
I'm trying to change the img on click. this is my html code:
<div id ="Nl">
<img id="imgNl" src="images/Nl.jpg">
</div>
this is the awnser I found:
<script>
$('#Nl').click(function(){
$('imgNl').attr('src', 'images/smiley.jpg');
});
</script>
It doesn't work. what did I do wrong?
Upvotes: 0
Views: 82
Reputation: 9281
You forgot the id selector '#'
$('#imgNl').attr('src', 'images/smiley.jpg');
for more info on selectors refer this
Upvotes: 5
Reputation: 56
your correct script is :-
<script>
$('#Nl').click(function(){
$('#imgNl').attr('src', 'images/smiley.jpg');
});
</script>
Upvotes: 0
Reputation: 2361
<script>
$('#Nl').click(function(){
$('#imgNl').attr('src', 'images/smiley.jpg');
});
</script>
missed the #
for id
Upvotes: 2