1

My code

   $( ".attachPo" ).click(function() {
        alert($(this).attr('id'))   // prints 59
        var id = $(this).attr('id');
        $( '#attachPoForm_"+id+"').show();  // id name = attachPoForm_59
    });

but which does not work for me , what is the correct vay of appending jQuesy variable to a class or id name

1
  • 1
    $('#attachPoForm_'+id) Commented Oct 15, 2013 at 12:13

6 Answers 6

3

Your quotes aren't quite right. Change to:

$( '#attachPoForm_'+id).show();

This isn't a "jQuery variable", it's just simple Javascript variable and string concatenation.

Sign up to request clarification or add additional context in comments.

Comments

1

Your selector is looking for an element with an id of (literally) #attachPoForm_"+id+", I think you mean:

$( '#attachPoForm_'+id).show();

Comments

1

Try this

$( ".attachPo" ).click(function() {
    var id = this.id
    $( '#attachPoForm_'+id).show();  // id name = attachPoForm_59
    //                ^^^^ Fixed the quotes here 
});

Comments

0
 $( ".attachPo" ).click(function() {
       $( '#attachPoForm_'+ $(this).attr('id')).show();  //set  id name = attachPoForm_59
    });

Comments

0

A mistake at

    $( '#attachPoForm_"+id+"').show();  // id name = attachPoForm_59

should be

    $( '#attachPoForm_'+id+'').show();  // id name = attachPoForm_59

Comments

0

Try to use this.id like,

$( ".attachPo" ).click(function() {
    var id=this.id;
    alert(id);
    $("#attachPoForm_"+id).show();  // id name = attachPoForm_59
});

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.