Jun Jie Wong
Jun Jie Wong

Reputation: 1

How do I make an hyperlink using an image with Jquery?

These are my codes. I'm trying to make a hyperlink using an image for my phonegap project. Appreciate any help as i'm a begginner in coding!

<!-Home Page->
       <div data-role = "page" id = "home">
      <div data-role = "header" data-theme ="b">
         <h1>Valentine's Day</h1>
         <a data-role = "button" href = "#Valentino" >Valentino</a>
      </div>
      <div data-role = "content">
         <p>Looking for something to get for your loved ones? </p>
         <a href ="#Valentino"></a><img src = "images/myimage.png" width="250" height="300" class="ui-li-icon"/>
      </div>
   </div>

Upvotes: 0

Views: 21

Answers (2)

Barmar
Barmar

Reputation: 781004

Use the jQuery() function to create elements, specifying the attributes and contents in the second argument.

var link = $('a', {
    href: '#Valentino',
    html: $('img', {
        src: 'images/myimage.png',
        width: 250,
        height: 300,
        "class": 'ui-li-icon'
    }),
});
$("#someDiv").append(link);

Upvotes: 2

rioc0719
rioc0719

Reputation: 303

Simply place the <img> inside the <a>:

<a href="#Valentino">
  <img src="images/myimage.png" width="250" height="300" class="ui-li-icon" />
</a>

Upvotes: 0

Related Questions