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

  • SEARCH
  • Home
  • 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 466743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:30:39+00:00 2026-05-12T23:30:39+00:00

pic_display+=<img src=’+pic_url+’ onClick=’swapImage(+pic_url+);’> I am adding an image to the innerHTML of a div

  • 0
pic_display+="<img src='"+pic_url+"' onClick='swapImage("+pic_url+");'>

I am adding an image to the innerHTML of a div with the code above.
I want to call the function swapImage(pic_url) whenever I click on the image.

I have still not figured out the syntaxes in javascript, always confuse them with php.

How should it be written ?

Thanks

  • 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-05-12T23:30:40+00:00Added an answer on May 12, 2026 at 11:30 pm

    You need to wrap the function argument in quotes like you have with the src attribute. For example.

      pic_display+="<img src='"+pic_url+"' onClick='javascript:swapImage(\""+pic_url+"\");'>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code : <a href=javascript:document.forms['form1'].student_pic.click()> <img src=images/mypic.png alt= width=161 height=29 border=0 style=margin-top:10px
The img src that I need to grab is: div id=recaptcha_image class=width: 300px; height:
I am using the HTML IMG tag to source/link an image and I want
When I run this following code on a sample image(RGB), and then process it
I have an INPUT text field, a DIV and an IMG. The IMG has
body{ background-size: 100%; background-image:url('../img/back.png'); } .school{ font-size:45px; margin: 20px 20px; color:#696969; font-weight:600; } .date{
Whats going wrong with my explorer or mozilla. I used the <img src=path/> but
$(document).ready(function() { $(img.resizeImage).each(function(){ var img = $(this); var width = $(this).width(); // Current image
I have set the target of the pic_form to a div (pic_target). The form
I want to split two pictures (pic A and pic B - both same

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.