jQuery can't get a good formatted Id
I have a problem with this fonction:
function test(value){
var id = "'" + value + "'";
$(id).remove()开发者_高级运维;
}
It gets an "Id", add simple quotes and then call the remove function.
The "value" is a generated id by php. For example, I can have:
$var = "$the_id";
When the "test" function is triggered by a click, I get te following error:
Uncaught Syntax error, unrecognized expression: ''
I thought it's because the function cannot get the id. But when I insert an alert in the function ( alert (id) ), it returns the right "id" with the good format ( '#the_id').
How can solve this problem?
Thank you,
regards.
Assuming the value argument to your function is the id then you want to change your function to:
function test(value){
var id = "#" + value;
$(id).remove();
}
If the value is already a string of "#the_id"
then you don't need to quote it.
精彩评论