1

I am using this to point a seperate td's in a table. And the id(dynid) are created dynamically so i need to change the position to absolute when user hover on a td. And i tries the below one but its not wroks

$('#selectTable tr td #td'+dynid).hover(

 function () {

   $(this).css("position","absolute");

 }
);

Thanks in advance

3
  • Can you post a sample of the generated HTML? So your IDs are like this? <td id="td3423"> where 3423 is the dynid ? Commented Apr 28, 2012 at 9:35
  • Are you sure about the way you select your elements? Maybe just $('#td'+dynId)? Commented Apr 28, 2012 at 9:41
  • @Smamatti: Yes like yours only it will generated Commented Apr 28, 2012 at 9:42

2 Answers 2

2

You are looking for an element within the td element, but you want the td element with a certain id. There is whitespace. You need td#id instead of td #id.

dynid = 2; // Test

$('#selectTable tr td#td' + dynid).hover(
    function () {
        $(this).css("position","absolute");
    }
);

A sample with background-color
http://jsfiddle.net/FKhbd/

You may want to define a second handler, if the hover ends. Something like this:

$('#selectTable tr td#td' + dynid).hover(
    function () {
        $(this).css("position","absolute");
    },
    function () {
        $(this).css("position","relative");
    }
);
Sign up to request clarification or add additional context in comments.

Comments

0

Probably your selector is wrong: '#selectTable tr td #td'+dynid should become '#selectTable tr td#td'+dynid. You'd also be wise to toggle on and off a css class that sets position: absolute like so:

$("#selectTable td").hover(function () {
    $(this).addClass("pos-abs"); // focus
}, function () {
    $(this).removeClass("pos-abs"); // blur
});

See http://api.jquery.com/hover/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.