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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:41:12+00:00 2026-06-12T06:41:12+00:00

I am creating a div dynamically, then appending it to a container: var str

  • 0

I am creating a div dynamically, then appending it to a container:

var str = '<div class="dimsdiv" id="'+dim.src+'" cursor:pointer;"></div>'; 
$('#fpdiv').append(str);

Now I need to add a hover even to those divs. I tried to just reference it, but then found that I needed to consider .on() instead. I tried this (before on):

$('#'+dim.src).hover(function{},function{});

But as expected, that didn’t work. I also tried this:

$('#'+dim.src).on('hover','(function{},function{})');

but can’t seem to get the syntax just right. Can someone help here?
Thanks in advance.

  • 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-12T06:41:14+00:00Added an answer on June 12, 2026 at 6:41 am

    You may try this

    var str = $('<div/>', {
        text:'Hello',
        class:'dimsdiv',
        id:'dim_src',
        style:'cursor:pointer',
        mouseenter:function(){ ... },
        mouseleave:function(){ ... }
    });
    $('#fpdiv').append(str);
    

    Also remove the . from dim.src, instead use dim_src as id, it’s used as class selector in jQuery, not sure why you used it tho but $('#'+dim.src) is invalid.

    DEMO.

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

Sidebar

Related Questions

I am dynamically creating a div using jQuery and then adding a class to
I'm dynamically creating some <div> elements and then filling their innerHTML properties with text.
I am adding img tag dynamically in a container div. While creating img i
i am creating div using DOM Element as phototab = document.createElement('div'); phototab.setAttribute('class', 'phototab fleft');
After creating a div on the fly with this markup: $('.circuit').prepend(<div class='component' draggable='true'>TRANSISTOR</div>); It
Using jQuery in IE8, I'm creating a div with a class (ex. <div class=className></div>
I have a div Container, and I am creating a dynamic textbox control when
So I am creating a container with rounded corners using the following method: div.rounded
//dom <div id='toBeCloned'><span>Some name</span></div> <div id='targetElm'></div> //js $(function () { //creating a clone var
I am dynamically creating divs by incrementing their class names. Now i have a

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.