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?
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();
});
$(this).removeAttr('src') doesn't work, see my jsfiddle @ jsfiddle.net/KooiInc/duDxbvar first_img = $('<img alt="example"/>').attr('src',[...] )
.on('click',
function(){$(this).remove()}
);
see jsfiddle
first_imgtonull?