H Bellamy
H Bellamy

Reputation: 22705

ID is undefined but it isn't?

Please look at this fiddle: http://jsfiddle.net/DHts6/1/

Why does it say undefined, even though the id = "foo" is set!

Thanks

Upvotes: 0

Views: 3212

Answers (3)

Al W
Al W

Reputation: 7713

$(document).ready(function(){
$('b.edit').click(function(){
        $(this).hide().after('<form action = "foo.php" method = post><input name = "field" type = "text" value = "'+$(this).attr('id')+'"/><input type="text" name = "period" class="editP" value="'+$(this).html()+'" /><input type = "submit" value = "Submit!!" /></form>');
        $('.editP').focus();
    });
    $('.editP').live('blur', function(){
        $(this).hide().prev('b.edit').html($(this).val()).show();
    });
});

Upvotes: 0

Naftali
Naftali

Reputation: 146302

Use this.id not $(this).id:

http://jsfiddle.net/maniator/DHts6/2/

Upvotes: 1

Amir Raminfar
Amir Raminfar

Reputation: 34150

You don't need $(this).id, just do this.id.

Reason for this is that $ creates a jQuery object that doesn't have .id property. In jQuery you would use attr $(this).attr('id')

http://jsfiddle.net/DHts6/5/

Upvotes: 4

Related Questions