views:

435

answers:

1

I'm working on an application that requires a text field to fade in with the value being loaded by AJAX. (I'm doing this all with jQuery), here's the code:

$("div#p"+eId+"_content").html("<input class='editPost' type='text' value='"
                               + oldCont
                               + "' id='p"
                               + eId 
                               + "_editBox' />");

Unfortunatly, oldCont can contain single quotes, which means the textbox will only contain oldPost up until that single quote. How could I display oldCont without having that problem, but still retaining that single quote (without the \ from escaping it)?

+4  A: 
$("div#p"+eId+"_content")
  .append( $("<input type='text' id='p"+eId+"_editBox' />")
           .addClass('editPost').val(oldCont));

...I think those parens line up ..... :-)

basically, use the val function on a jquery object and it'll take care of the escaping for you. Similarly you can use the addClass, attr, etc. functions for other pieces of your html objects

Clyde
That did it except I needed to remove one of the parenthesis at then end.
Vestonian