X

LATEST #JQUERY NEWS

Show Image Preview for External Images Using jQuery


You must have seen on many websites that as soon as you enter any image URL, the image preview is displayed on the screen. This is a very good idea to let your user know exactly which image they are referring to. This can be easily done via jQuery. In this post, let’s find out how to show image preview for the input URL using jQuery.

To display the image preview on screen, along with the input text box, we also need to have image tag. So your HTML should look like:

<div>
Image Url: <input type="text" id="txtURL"/>
<br />
<img id="imgPreview" />
</div>

Here is the jQuery code which will display the image preview as soon as the focus goes out of the input text box. The idea is very simple. You just copy the entered URL and assign the same to image element as the source and image will be loaded.

$(document).ready(function(){
  $('#txtURL').change(function () {
    $('#imgPreview').attr('src', $('#txtURL').val())
  }) 
});

So now, when you run your application and enter any valid image URL to input box and as soon as the focus goes out, the image URL will be assigned to image tag and it will be displayed.

Recently Published

article image
»

7 Responsive jQuery Dropdown Menu Plugins

Dropdown Menu Plugins Dropdown menus are mostly used for website ...

article image
»

20 Stylish and Modern jQuery Tooltip Plugins

jQuery Tooltip Plugins Tooltips are a great option for showing extra ...

article image
»

15 Newest jQuery plugins for responsive website

Due to the proliferation of smartphones and tablets, responsive ...

article image
»

How to use Redux with jQuery

State management is one of most integral parts of any software and a ...

article image
»

Fade HTML Table Row on Hover Using jQuery

HTML tables are the ideal choice for displaying data in tabular form. ...

article image
»

Drag and Drop HTML Table Rows Using jQuery

HTML tables are the preferred UI option for displaying data. Sorting, ...

article image
»

Top 5 Best JavaScript Template Engines

Template engines help in the decoupling of HTML and JavaScript code ...

article image
»

3 jQuery/JavaScript Plugins for Push Notifications

Push notifications started from the mobile business but this ...

article image
»

Create Smooth Animation Using jQuery’s “stop()”

Making Quick Work jQuery’s animate() method is a quick way to ...