How to replace anchor text inside aps.net label?

How to replace the internal anchor tag tag inside the Asp.net tag:

Example:

<asp:Label ID="AER_UI_Exam_MPN_ThreeAttemptsBefore_1" runat="server" Text="Please visist: <a id='google'class='translatetext lblfont' href='https://google.com' target='_blank' style="font-size: 12px;">google</a>" CssClass="lblfont translatetext" Style="font-size: 12px;" /> 

if i get class based id

 $(".translatetext").each(function () { var id = this.id; dictionary[id] = $("#" + id + "")[0].innerText; }); 

I get both identifiers, but the anchor tag is replaced as text, not as a link. here during debugging, I found that for the first id -innertext: Please visist:google , when this inner text is replaced with

  "some text" 

second identifier not found for anchor . how to deal with this scenario?

Result: Please see: google,

Expected Result: Please see: [google]

+5
source share
2 answers

Hi, please try this.

  <asp:Label ID="AER_UI_Exam_MPN_ThreeAttemptsBefore_1" runat="server" CssClass="lblfont translatetext" Style="font-size: 12px;"> Please visist: <a id='google'class='translatetext lblfont' href='https://google.com' target='_blank' style="font-size: 12px;">google</a></asp:Label> 

Edited by:

First, you create an anchor tag in jQuery. Like this.

  var myhtml="Please visist: <a id='google' class='translatetext lblfont' href='https://google.com' target='_blank' style='font-size: 12px;'>"+some text+"</a>"; 

then assign the above variable to this label.

 $("#AER_UI_Exam_MPN_ThreeAttemptsBefore_1").html(myhtml); 
+3
source

If you want to wrap text with a square bracket, use, for example,

 $(".translatetext").each(function() { $(this).text("[" + $(this).text() + "]"); }); 
0
source

Source: https://habr.com/ru/post/1247348/


All Articles