Jorge
Jorge

Reputation: 18237

replace it's not working

i don't know what's the cause but i just want to replace the caraceters with this values but i doesn't work could anybody see what i'm doing wrong??

$(document).ready(initialize);

function initialize() {
    $messageValues = $("#messagePreview");
    $("#txtMessageFields").keyup(previewData);

}

function previewData() {
    $messageValues.html('');
    var aux = this.value;
    aux.replace("#", '<span class="fieldText">');
    aux.replace('!', '</span>');
    $messageValues.append('<p>' + aux + '</p>');
}

thanks for your time

Upvotes: 0

Views: 172

Answers (2)

Thomas Shields
Thomas Shields

Reputation: 8942

replace is a function that returns a value; it doesn't modify the original string. Instead, assign aux to the value returned by replace:

 aux = aux.replace("#", '<span class="fieldText">');
    aux = aux.replace('!', '</span>');

Upvotes: 4

Brandon
Brandon

Reputation: 69983

.replace doesn't change the original string, it returns the modified string. You need to assign the returned value to something:

aux = aux.replace("#", '<span class="fieldText">');
aux = aux.replace('!', '</span>');

Upvotes: 3

Related Questions