views:

28

answers:

2

Hi everybody,

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.

+2  A: 

If the value is already a string of "#the_id" then you don't need to quote it.

scunliffe
+2  A: 

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();
}
thatismatt