Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8556545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:22:36+00:00 2026-06-11T15:22:36+00:00

To have an image which acts as a javascript trigger there are quite a

  • 0

To have an image which acts as a javascript trigger there are quite a few options:

(EDIT: using inline css & javascript for simplifying the question)

Image in anchor tag:

<a href="#" onclick="myFunc();"><img src="pic.jpg" /></a>

Img tag with properties:

<img style="cursor:pointer" onclick="myFunc();" />

Anchor tag with properties:

<a href="#" onclick="myFunc();" style="background:url('pic.jpg');"></a>

Possibly others as well. Is there a (convention|best practice|widely accepted|fail safe) way to go on with this?

I want a small image to act as a button to run certain Javascript or AJAX.

BTW, I’ve seen this but it’s not what I’m looking for, he talks about header elements, not links.

Related: Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:22:38+00:00Added an answer on June 11, 2026 at 3:22 pm

    If I were you I’d stick with your first choice with a few changes

    <a href="javascript:void(0);" onclick="myFunc();"><img src="pic.jpg" border="0" /></a>

    Reasons for this are as follows

    • href=”#” still allows clickthrough if your myFunc fails
    • javascript:void(0) doesn’t allow clickthrough
    • javascript:void(0) is cross-browser
    • javascript:void(0) still allows basic implied anchor tag behaviour
    • attribute/properties on the image tag will be recognised by most browsers but some older versions of IE may not like it
    • if you want to use a background image that’s upto you, but it’ll mean additional CSS to control height/width

    Additionally, if you use jQuery or some other library, then I’d recommend doing it via

    $(document).on('ready, function() {
    $('#myAnchorId').on('click', myFunc);
    });

    Instead of doing via HTML props… just in case the user has JavaScript turned off

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image which is pretty much b&w and it has a black
I have a JQuery script which acts as a simple image rollover with a
I have an image which is square 100px by 100px. Was wondering if there
I have this div which acts a lens in zooming of the image. But
I have a image which has an mouseover jquery function: $(document).ready(function ()) { mouseenter:
I have an image which is made up of 2 images, a sprite. What
I have an Image which I am translating along the X , with the
I have an image which is placed in the middle of the screen all
I have an image which is just made of one color ? (it could
I have an image which is added to the project. In the simulator it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.