How to change label text?

I try to change label text but nothing works

  function changeText(lblTxt) {

        var lblAjaxUpdate = $("#" + Key).find("[class='label']");//finds the label no problem

        lblAjaxUpdate.attr('text', lblTxt);// don't work
        lblAjaxUpdate.InnerText = lblTxt;//don't work
        lblAjaxUpdate.InnerHtml = lblTxt;//don't work
        lblAjaxUpdate.value = lblTxt;// and...don't work :(       
    }

What am i doing wrong ? do i miss something?

Answers:

Answer

You need .text()

lblAjaxUpdate.text(lblTxt);

You can also use InnerText on DOM object but not on jQuery object, use indexer or .get() to convert the jQuery object to DOM

lblAjaxUpdate[0].InnerText = lblTxt;
lblAjaxUpdate[0].InnerHtml = lblTxt;

OR

lblAjaxUpdate[0].get(0).InnerText = lblTxt;
lblAjaxUpdate[0]..get(0).InnerHtml = lblTxt;
Answer

in your case:

lblAjaxUpdate.text(lblTxt)

or

lblAjaxUpdate.get(0).InnerText = lblTxt
Answer

A basic use with

$('label').text();

is shown here http://jsfiddle.net/aCQg9/

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.