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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:37:23+00:00 2026-05-27T12:37:23+00:00

var left=10; var right=50; $(#leftori).attr(id,left); $(#rightori).attr(id,right);//change the id $(document).delegate(‘div[id^=’+left+’]’, ‘mouseenter’,function() { alert(left ok!); var

  • 0
var left=10;
var right=50;
$("#leftori").attr("id",left);
$("#rightori").attr("id",right);//change the id

$(document).delegate('div[id^='+left+']', 'mouseenter',function() {
  alert("left ok!");
  var newleft=left+1;
  $("#"+left).attr("id","newleft"};//change the id
  left=newleft;
 }
$(document).delegate('div[id^='+right+']', 'mouseenter',function() {
  alert("right ok!");
  var newright=right+1;
  $("#"+right).attr("id","newright");
  right=right+1;
}

<body>
<div id="leftori" class="div01"></div>
<div id="rightori" class="div01"></div>
</body>

The Questions are:

  1. How can I delegate the dynamical “id” on the new div which changed the id attribute on the second mouseenter event?
  2. I want to combine the selector with the id^=left or id^=right in the same delegate function . Can any method to make it? For example:

    $(document).delegate('div[id^='+left+']' || 'div[id^='+right+']' , 'mouseenter',function() {...}

But it cannot work well…How can I fix it or not have other method but to write in two delegate functions?

  • 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-27T12:37:23+00:00Added an answer on May 27, 2026 at 12:37 pm

    I would suggest that you don’t change the ID of any DOM element – there are far better ways to keep “data” on a DOM element ….

    How about something like this :

    HTML :

    <div id="container">
       <div id="leftori" class="left"></div>
       <div id="rightori" class="right"></div>
    </div>
    

    JavaScript :

    var left=10;
    var right=50;
    // store the data
    $("#leftori").data("num",left);
    $("#rightori").data("num",right);
    
    $('#container').on('mouseenter','div',function() { 
        // update the data on mouseenter
        if ($(this).hasClass('left')){
            console.log('left');
            left++;
            $(this).data('num',left);
            console.log(left); 
            // or console.log($(this).data('num')); to access the new number
        } else if($(this).hasClass('right')) {
            console.log('right');
            right++;
            $(this).data('num',right);
            console.log(right);
            // or console.log($(this).data('num')); to access the new number
        }
    });
    

    Incase you are not aware – the console.log command logs the output to the browsers javascript console of a debugger (firebug).

    docs

    • on() -> replacement for delegate in jQuery 1.7
    • data() -> storing info on DOM elements
    • hasClass() -> check if the DOM element has a specific class

    Working example : http://jsfiddle.net/8RhbB/1/

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

Sidebar

Related Questions

In the below code var panel=<div name=panel id=panel style=display:inline;position: absolute; margin-left: auto;margin-right:auto;left: 0;right: 0;width:350px;height:
Why doesnt this work $(#right).click(function(){ $(#sliderWindow).find(img).each(function(i) { var left = $(this).css(left); $(#imageContainer + i).animate({left:
I have a 3 col layout (fixed center, var Left & Right side cols)
var wdt = document.body.offsetWidth/2.6 var hgt = document.body.offsetHeight/4 $(#element).offset({left:wdt, top:hgt}) what i am trying
This code var offset = $('#snapwrap_inner').offset(); alert(offset.left) in FF returns 0px but in Opera
I have a function in jquery: $('#map').click(function(e) { var posX = $(this).offset().left, posY =
I have a function that calculates the left and right node values for some
I'm displaying pop up window using the below code: var left = (screen.width/2)-(400/2); var
This is fine, it produces a left join var q = from c in
var ref1 = new Firebase(http://gamma.firebase.com/myuser/123,456); ref1.set(123,456); var on1 = ref1.on(value, function(snapshot) { console.log(snapshot.val()); });

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.