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
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
Share asked Oct 15, 2013 at 12:11 mondamonda 3,91516 gold badges61 silver badges85 bronze badges 1-
1
$('#attachPoForm_'+id)
– mikakun Commented Oct 15, 2013 at 12:13
6 Answers
Reset to default 3Your 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.
Your selector is looking for an element with an id of (literally) #attachPoForm_"+id+"
, I think you mean:
$( '#attachPoForm_'+id).show();
Try this
$( ".attachPo" ).click(function() {
var id = this.id
$( '#attachPoForm_'+id).show(); // id name = attachPoForm_59
// ^^^^ Fixed the quotes here
});
$( ".attachPo" ).click(function() {
$( '#attachPoForm_'+ $(this).attr('id')).show(); //set id name = attachPoForm_59
});
A mistake at
$( '#attachPoForm_"+id+"').show(); // id name = attachPoForm_59
should be
$( '#attachPoForm_'+id+'').show(); // id name = attachPoForm_59
Try to use this.id like,
$( ".attachPo" ).click(function() {
var id=this.id;
alert(id);
$("#attachPoForm_"+id).show(); // id name = attachPoForm_59
});