Reputation: 1611
I'm storing an image value in the variable first_img
:
var first_img = $('img[alt="example"]').attr('src');
And I want to set the value null
after the button is clicked JavaScript or jQuery.
How can I do this?
Upvotes: 0
Views: 10884
Reputation: 123
Try this:-`enter code here`
***$('img[alt="example"]').click(function() {
$(this).removeAttr('src');
});***
Upvotes: 1
Reputation: 122906
var first_img = $('<img alt="example"/>').attr('src',[...] )
.on('click',
function(){$(this).remove()}
);
see jsfiddle
Upvotes: 1
Reputation: 318212
Not sure I get this at all, as it sounds kinda obvious?
var first_img = $('img[alt="example"]').attr('src');
$('button').on('click', function() {
first_img = null;
});
Upvotes: 1
Reputation: 1038840
You could remove the src
attribute when the image is clicked:
$('img[alt="example"]').click(function() {
$(this).removeAttr('src');
});
or completely remove the <img>
tag from the DOM:
$('img[alt="example"]').click(function() {
$(this).remove();
});
Upvotes: 1