Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $(this).attr() trouble

    Code:
    $(document).ready(function() {
    	$(".alert").click(function() {
    		{
    			var id = $(this).attr("id");
    			alert(id);
    			$(id).dialog();
    			return false;
    		}
    	});
    });
    Ok it's alerting the id AFTER it alerts an undefined.. so it alerts "undefined" and then "5" or whatever the number may be.
    What am I doing wrong?

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,606
    Thanks
    6
    Thanked 997 Times in 970 Posts
    How many elements with class “alert” do you have in your document? Maybe the first match doesn’t have an ID?

    Also, IDs must not start with a number, only with letters A–Z or a–z.

  • #3
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 565 Times in 558 Posts
    If your id=="5" (which is not a proper id), what the heck do you expect
    Code:
    $(id).dialog()
    to do?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •