Careless Careless - 6 months ago 4x
Javascript Question

Replace var with some new var jquery

I have code to find something from database and output it back if it exists.
Now when I output it back I need to make on click one of those outputs replace that output as var in some other var.

$(document).ready(function() {
$("#leavepost").keypress(function(event) {
var key = (event.keyCode ? event.keyCode : event.which);
if (key == 35) {
$('#leavepost').on('keyup', function() {
var matches = $(this).val().match(/(^|\s)(#[a-z\d-]+)/ig)[0];
var name = matches;
type: "POST",
url: "d/sul.php",
data: {
su: name
success: function(sss) {
$(".adduser").click(function() {
var username = $(this).text();
var a = username;
var username2 = $(this).attr('id');
var E = "<a class='red' contenteditable='false' href='#' >" + a + "</a>";
var content = name.replace(name, E);

When I click on class div hides but before that nothings happend... I need to replace #word from var name witdh var E.


Your problem is most likely because you used .html() in on a <textarea> as stated in the discussion.

  $("#choices li").click(function(){
    var name = $(this).text();
    $("#ta").val($("#ta").val().replace("#thisperson", name));

Changing the .html() bit with .val() will fix the problem.