[javascript] How to change the text of a label?

I have a radiobutton list and on click on the radio button item I have to change the text of its label. But for some reason it's not working. Code is below:

<asp:Label ID="lblVessel" Text="Vessel:" runat="server"></asp:Label>

<script language="javascript">
  $(document).ready(function() {

    $('#rblDiv input').click(function() {
      var selected = $("#rblDiv input:radio:checked").val();
      if (selected == "exportpack") {
        $('#lblVessel').text("NewText");
      }
    });
  });
</script>

This question is related to javascript jquery html asp.net label

The answer is


we have to find label tag for attribute value based on that.we have replace label text.

Script:

<script type="text/javascript">
$(document).ready(function() 
{ 
$("label[for*='test']").html("others");
});

</script>

Html

<label for="test_992918d5-a2f4-4962-b644-bd7294cbf2e6_FillInButton">others</label>

You want to more details .Click Here


try this

$("label").html(your value); or $("label").text(your value);


$('#<%= lblVessel.ClientID %>').html('New Text');

ASP.net Label will be rendered as a span in the browser. so user 'html'.


I was having the same problem because i was using

$("#LabelID").val("some value");

I learned that you can either use the provisional jquery method to clear it first then append:

$("#LabelID").empty();
$("#LabelID").append("some Text");

Or conventionaly, you could use:

$("#LabelID").text("some value");

OR

$("#LabelID").html("some value");

   lable value $('#lablel_id').html(value);

I just went through this myself and found the solution. See an ASP.NET label server control actually gets redered as a span (not an input), so using the .val() property to get/set will not work. Instead you must use the 'text' property on the span in conjuntion with using the controls .ClientID property. The following code will work:

$("#<%=lblVessel.ClientID %>").text('NewText');

Try this:

$('[id$=lblVessel]').text("NewText");

The id$= will match the elements that end with that text, which is how ASP.NET auto-generates IDs. You can make it safer using span[id=$=lblVessel] but usually this isn't necessary.


<asp:RadioButtonList ID="rbtnType" runat="server">
    <asp:ListItem Value="C">Co</asp:ListItem>
    <asp:ListItem Value="I">In</asp:ListItem>
    <asp:ListItem Value="O">Out</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:Label ID="lblLabelName" runat="server"></asp:Label>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<%=rbtnType.ClientID%>").change(function() {
            var rbvalue = $("input[@name=<%=rbtnType.ClientID%>]:radio:checked").val();
            if (rbvalue == "C") {
                $('#<%=lblLabelName.ClientID %>').html('text1');
            } else if (rbvalue == "I") {
                $('#<%=lblLabelName.ClientID %>').html('else text2');
            } else if (rbvalue == "O") {
                $('#<%=lblLabelName.ClientID %>').html('or elsethistext');
            }
        });
    });
</script>

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to jquery

How to make a variable accessible outside a function? Jquery assiging class to th in a table Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Getting all files in directory with ajax Bootstrap 4 multiselect dropdown Cross-Origin Read Blocking (CORB) bootstrap 4 file input doesn't show the file name Jquery AJAX: No 'Access-Control-Allow-Origin' header is present on the requested resource how to remove json object key and value.?

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to label

How to set label size in Bootstrap How do I change the text size in a label widget, python tkinter Change grid interval and specify tick labels in Matplotlib Editing legend (text) labels in ggplot How to change Label Value using javascript React ignores 'for' attribute of the label element How to dynamically update labels captions in VBA form? why I can't get value of label with jquery and javascript? What does "for" attribute do in HTML <label> tag? Get Application Name/ Label via ADB Shell or Terminal