You could make use of the Javascript DOM API. In particular, look at the createElement() method.
You could create a re-usable function that will create an image like so…
function show_image(src, width, height, alt) { var img = document.createElement("img"); img.src = src; img.width = width; img.height = height; img.alt = alt; // This next line will just add it to the <body> tag document.body.appendChild(img); }
Then you could use it like this…
<button onclick= "show_image('http://google.com/images/logo.gif', 276, 110, 'Google Logo');">Add Google Logo</button>
See a working example on jsFiddle: http://jsfiddle.net/Bc6Et/
Related Posts:
- Resize image with javascript canvas (smoothly)
- JavaScript: Get image dimensions
- Edit webpage with javascript trick – how to “unedit”?
- Embed image in a
- Automatically pausing html5 video as the ‘next’ button is pressed (javascript/ jquery)
- Is it possible to write data to file using only JavaScript?
- Image is not showing in browser?
- Remove CSS class from element with JavaScript (no jQuery) [duplicate]
- Is it possible to write data to file using only JavaScript?
- How to make JavaScript execute after page load?
- Set cookie and get cookie with JavaScript
- forbidden 403 on image URLS
- Which is better: or
- Onclick javascript to make browser go back to previous page?
- How to make JavaScript execute after page load?
- Is element block level or inline level?
- Why is my Javascript not working?
- How do I auto-resize an image to fit a ‘div’ container?
- CSS Display an Image Resized and Cropped
- How to place a text next to the picture?
- How to put a text beside the image?
- How can I get the values of data attributes in JavaScript code?
- CSS: Moving the text down a few pixels but keeping the background still?
- Javascript: getElementById vs getElementsById (both works on different pages)
- mailto using javascript
- mailto using javascript
- Mailto using Javascript?
- How to change css property using javascript
- javascript close current window
- Bootstrap 4 images thumbnail classes
- CSS: Moving the text down a few pixels but keeping the background still?
- Rotate an image in image source in html
- Programmatically change the src of an img tag
- display variable image using cookies
- CSS Background image not loading
- How to “crop” a rectangular image into a square with CSS?
- I am trying to make a simple toggle button in javascript
- How to call a JavaScript function within an HTML body
- What formats can be displayed with type=”application/x-shockwave-flash”
- How to save user input into a variable in HTML and JavaScript
- Hiding a button in Javascript
- Show/hide ‘div’ using JavaScript
- CSS centred header image
- How to make JavaScript execute after page load?
- Get HTML code using JavaScript with a URL
- Calculate percentage Javascript
- JavaScript function onhover in
- Check if an element contains a class in JavaScript?
- Hide element by class in pure Javascript
- How to play a mp3 using Javascript? [duplicate]
- mailto using javascript
- Function not defined javascript
- How to submit a form with JavaScript by clicking a link?
- How to call a REST web service API from JavaScript?
- Check a radio button with javascript
- Wrap text around bootstrap image
- AppendChild() is not a function javascript
- How can I change an element’s class with JavaScript?
- Showing an image from an array of images – Javascript
- Is it possible to set the equivalent of a src attribute of an img tag in CSS?
- Why write script type=”text/javascript” when the mime type is set by the server?
- How to add image that is on my computer to a site in css or html?
- How to display Base64 images in HTML
- How to select an input element by value using javascript?
- Making an image act like a button
- javascript window.location in new tab
- Display text on MouseOver for image in html
- HTML5 Canvas Rotate Image
- HTML tag is not working
- How to create a hidden in JavaScript?
- Tooltip on image
- How do I programmatically set the value of a select box element using JavaScript?
- Display text on MouseOver for image in html
- How can I capture the right-click event in JavaScript?
- How do I clear the content of a div using JavaScript?
- How to make a monopoly board using css grid?
- How do I add an image to an HTML file?
- Adding attribute in jQuery
- Set timeout for ajax (jQuery)
- CSS horizontal scroll
- How to outline text in HTML / CSS
- Play videos with iframe in html
- Vue is not defined
- How do I check if an object has a key in JavaScript?
- Is there a command for formatting HTML in the Atom editor?
- How to write inside a DIV box with javascript
- How to show text on image when hovering?
- What’s the difference between using NAV and DIV around Bootstrap 3 navbars?
- How to call a webservice method from an html page [javascript] with out refresh the page
- Absolute position is not working
- Position absolute but relative to parent
- When is a CDATA section necessary within a script tag?
- How to wrap the content of the main tinyMCE editor with extra tags
- how to insert a HTML form into a javascript popup?
- How to remove auto generated markup? [closed]
- Is there a common structure for a wordpress formular?
- Is it possible to isolate and use WordPress functions outside of wordpress
- Search bar for wp menu
- sessionStorage saves input value in browser but it is not loaded in the form field