Add images with jQuery
Add images with jQuery
I would like to have a jQuery function with a set of images that I call from my HTML file, so if I need to change a image of my set and can do it without having to go to all the HTML files where the code is copied.
Let say that I would like to have my site in 2 languages: Spanish and Portuguese and I have the two flags with the links. Then I would have to have this code in every single HTML page in my site.
- <a href=""><img src="https://lh6.googleusercontent.com/-TVVXgEf-NEw/ULpIJrV50uI/AAAAAAAAB_I/eciCwNvhIwo/s400/bandera%2520espania.jpg" height=15 width=20></a><a href=""><img src="https://lh6.googleusercontent.com/-R2pHG7auPl0/ULpIJxMk2GI/AAAAAAAAB_M/M2IEVnN5q0E/s594/bandera-brasil-3.jpg" height=15 width=20></a>
I would like to be able to convert the code above to a jQuery code, so If I want to add or remove a "language" --> image with the link I don't have to change it in every single HTML page but only in the jQuery file.
Something like the following but that actually works, because this is not working:
- $.fn.Languages = function(options) {
return this.each(function() {
var defaults = {images: [
'<a href="page1.html"><img src="https://lh6.googleusercontent.com/-TVVXgEf-NEw/ULpIJrV50uI/AAAAAAAAB_I/eciCwNvhIwo/s400/bandera%2520espania.jpg" height=15 width=20></a>',
'<a href="page2.html"><img src="https://lh6.googleusercontent.com/-R2pHG7auPl0/ULpIJxMk2GI/AAAAAAAAB_M/M2IEVnN5q0E/s594/bandera-brasil-3.jpg" height=15 width=20></a>']};
var settings = $.extend(defaults, options || {});
$(this).append(settings.images)];
});
};
Thank you very much