With JavaScript you can dynamically create every HTML element that you want. Here is an example on how to create a link with an image:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Create a link with an image in JavaScript</title> <style type="text/css"> .googleImage{ border: 2px solid blue; } </style> </head> <body> <script type="text/javascript"> // Link var link = document.createElement('a'); link.href = 'http://www.google.de/'; // Alternative: link.setAttribute('href', 'http://www.google.de/'); // Image var image = document.createElement('img'); image.className = 'googleImage'; image.src = 'http://www.google.de/images/logo.png'; // Create a link with an image inside link.appendChild(image); // Display the link document.body.appendChild(link); </script> </body> </html> |