Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1097887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:29:53+00:00 2026-05-17T00:29:53+00:00

i have a asp label in my page .i like to set some text

  • 0

i have a asp label in my page .i like to set some text in it with jquery .

<asp:label id="lblError" runat="server" CssClass="error" />

Which method will i use.

$(".error").text('hello'); 
or 
$(".error").html('hello');
or
$(".error").val('hello');

i am confused with all this ?plz help .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:29:53+00:00Added an answer on May 17, 2026 at 12:29 am

    If you’re using a master page or user control where the clientID will be different than what you defined in your .aspx page or possible that another element shares the same class, another option is:

    $("span[id$='lblError']").text('hello');
    

    To specifically answer the question though as noted already .text() is the most appropriate option as all 3 will work. It just semantically makes sense to use .text() to insert text rather than .html() since you are not inserting HTML.

    In terms of what actually happens would be another part of the answer now that I think about it a little more, and you can see this yourself by examining the jQuery script itself:

    .text() calls javascript function createTextNode with the string passed in and appends to DOM and does little else. //12 lines of code

    .html() does more processing for cleaning/processing of the string that is passed in. Also looks to have some code in place to prevent memory leaks. Also uses the innerHTML function of the browser. //38 lines of code

    One last note on the difference between .text() and .html() as seen on the API docs to differentiate the two is this line:

    Unlike the .html() method, .text() can be used in both XML and HTML documents.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have a asp label <asp:Label ID=lblstarUKRollNo Visible=false runat=server Text=* CssClass=star></asp:Label> and i want
I have asp label in my asp page and its text is some my
I have the following piece of asp: <asp:ValidationSummary ID=RegisterUserValidationSummary runat=server CssClass=failureNotification ValidationGroup=RegisterUserValidationGroup/> ... <asp:Label
i have a datalist control <ItemTemplate> <asp:Label ID=lblAddressID runat=server Text='<%# Bind(StudentName) %>'/> <asp:Label ID=lbl
I have a aspx page which contains the following CheckBoxList. <form id=form1 runat=server> <asp:CheckBoxList
I have a Label on a .Net page. <asp:Label ID=Label5 runat=server></asp:Label> The control has
I have a label on my asp.net page, it looks like this: more info
I use ASP.NET and have a label control on my page, which I fill
I have an ASP.NET website containing the following <asp:UpdatePanel ID=UpdatePanel1 runat=server > <ContentTemplate> <asp:Label
I have next code, <form id=form1 runat=server> <asp:Label runat=server ID=Label1 EnableViewState=false /> <asp:CheckBox runat=server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.