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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:49:46+00:00 2026-06-17T21:49:46+00:00

In my html I have <div id=map></div> #map { width: 100%; height: 100%; background-color:

  • 0

In my html I have

<div id="map"></div>

#map {
    width: 100%;
    height: 100%;
    background-color: #CCC;
}

that gets dynamically filled with several divs like the following

<div class="basicTiles1" style="left: 8128px; top: 8128px;"></div>

.basictiles1 {
    position: absolute;
    width: 64px;
    height: 64px;
    background-image: url(<snip urlToPng>);
    background-position: 0px 0px;
}

Then an onmousedown event is added to #map like so

$('#map').on('mousedown', function(){console.log("mousedown");});

The event is never triggered. If I don’t add the tiles to the map, it works.

I tried doing it with jquery’s ‘on’, ‘onmousedown’, javascripts ‘addEventListener’.
The script doesn’t have any compilation errors. The event just doesn’t seem to trickle down.

Is it because the tiles are position absolute? Is it because they are added dynamically?

  • 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-17T21:49:47+00:00Added an answer on June 17, 2026 at 9:49 pm

    I understand that when you bind the event, the DIV’s are not there yet. Try using delegate instead, like this:

    $("#map").delegate("div", "mousedown", function() {
        console.log("mousedown");
    });
    

    EDIT: Elaborating
    The jQuery .on() reference states: “Attach an event handler function for one or more events to the selected elements.”

    Moreover, when you bind the event directly to your #map it will work as long as you don’t cover it with something else (you have to mousedown ON the actual #map element).

    The jQuery .delegate() reference states instead: “Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.”

    Since you will be adding inner div’s -after- binding the event, this exactly fits what you want to do. Specifying the “div” selector actually binds mousedown to any (current or future) div inside #map. You could actually use div.basictiles1 if you have other, non-clickable divs there.

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

Sidebar

Related Questions

have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I am using http://code.google.com/p/jquery-ui-map/ HTML: <div id=map_canvas style=width: 100%; height:400px; latitude=123456 longitude=123456>Loading Map</div> jQuery
here's the code: HTML: <body onload=initializeMap()> <div id=map_canvas style=width:100%; height:100%; z-index:1></div> <canvas id=control style=width:100%;
in my html page I have div with css: padding: 0px; color: rgb(51, 51,
I have a div that is created by Ajax with .append(html) function, I'm trying
I have a page with height 100%: <div id=wrapper> <header id=header class=clearfix> </header> <div
Im trying to get google maps to show 100% width and height. I have
In the below shown html i have this main div as cxfeeditem feeditem and
i have animated div in html. it is adding 1px to div in every
I have a div element in an HTML document. I would like to extract

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.