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 8082215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:00:50+00:00 2026-06-05T17:00:50+00:00

I am using jquery and I would like to find the src of the

  • 0

I am using jquery and I would like to find the src of the image that I click on but I would also like to be able to click on the outerdiv and not just click on the image itself. My code is all here and can be copied and pasted into an editor. This is simplified code but my project generates the tags from a database and output to the webpage using PHP. It works fine if I click on the image but not if I click on the innerdiv or outerdiv. Any help would be greatly appreciated, I’m just begining to use jquery,
Thanks.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Jquery Select src</title>

    <script type="text/javascript" language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" language="javascript">
      $(document).ready(function() {
          $(".outerdiv img").click(function(){  //output variable 'theImage' when outerdiv is clicked
              var theImage = $(this).attr('src');
              alert("The image source is: " + theImage);
          });
  }); //end of document ready function
    </script>

    <style>
        .outerdiv {width: 300px; height: 200px; border: thin solid #000000;}
        .innerdiv {width: 160px; height: 160px; border: thin solid #0099FF;}
        .innerdiv img {width: 120px; height: 120px; border: thin solid #FF3300;}
    </style>

</head>

<body>

<div class="outerdiv">outerdiv
    <div class="innerdiv">innerdiv
        <img src="image1.jpg">
    </div><!--/innerdiv-->
</div><!--/outerdiv-->

<div class="outerdiv">outerdiv
    <div class="innerdiv">innerdiv
        <img src="image2.jpg">
    </div><!--/innerdiv-->
</div><!--/outerdiv-->

<div class="outerdiv">outerdiv
    <div class="innerdiv">innerdiv
        <img src="image3.jpg">
    </div><!--/innerdiv-->
</div><!--/outerdiv-->

</body>

</html>
  • 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-05T17:00:52+00:00Added an answer on June 5, 2026 at 5:00 pm
      jQuery(".outerdiv").add("innerdiv").add("img").click(function (){
        var target = $(this);
        var src = target.attr("src") || target.find("img").attr("src");
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a mobile-friendly website using jQuery Mobile but would like to do
I would like to upload a file using JQuery-File-Upload, but using HTTP PUT instead
I am using JQuery and would like to do the following. I have 2
I am new to using jquery and would like to know how to append
I am using jQuery autocomplete and would like to limit the showing results only
I'm using jQuery Validate and would like to re-validate a group of fields whenever
Using jQuery Nearest Element , I would like to select elements in a circular
I would like to play/pause video using jquery. Here is my code: (function ($)
I'm using JQuery mobile and I would like to raise an event when the
I would like to print the selected values of all selects using jQuery. I

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.