Search code examples
javascriptjqueryhtmlgwtgxt

insert image before the label and provide hyperlink on image?


I am using gwt. i need give an "remove" image before the label as below.

enter image description here

How i can wrap image before the text and provide hyperlink on an image?


Solution

  • It can be done using .prepend() and .append():

    $('p').prepend(
        $('<a></a>', { href : "http://google.com" }).append(
            $('<img />',  { src : 'http://placehold.it/30x30' })
        )
    );
    

    Demo

    In this example I have targeted <p> elements, so you will obviously need to change the selector according to what element you want to target (e.g table cell, list item?). What this does is first creates an image element and gives it a source, then creates an anchor element with a href, then appends the image to the anchor and finally prepends the anchor to the paragraph elements.