Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQUery - insert   inside label

Tags:

jquery

I want to hide a label using the fadeOut effect but when it is completed I want to insert inside it a  

 $('label.alert').fadeOut('slow',function(){$(this).text(' ');}); 

but it produces a   as a raw text. Any ideas ?

like image 719
Tony Avatar asked Aug 14 '12 14:08

Tony


People also ask

What is insertAfter in jQuery?

jQuery insertAfter() Method The insertAfter() method inserts HTML elements after the selected elements. Tip: To insert HTML elements before the selected elements, use the insertBefore() method.

What does $() mean in jQuery?

In jQuery, the $ sign is just an alias to jQuery() , then an alias for a function. This page reports: Basic syntax is: $(selector).action() A dollar sign to define jQuery.

How append a div in another div using jQuery?

First, select the div element which need to be copy into another div element. Select the target element where div element is copied. Use the append() method to copy the element as its child.

How do you create a new paragraph in jQuery?

Create a paragraph element with some text and append it to the end of the document body using jQuery. JavaScript Code : $( "p" ). add( "<span>Exercises</span>" ).


2 Answers

Use .html() instead of .text().

like image 143
fredrik Avatar answered Sep 22 '22 17:09

fredrik


Be careful with using .html() or the same methods using another framework/library (e.g v-html in Vue.js), because it has XSS vulnerability. Read more about XSS from this answer.

Working way via .text():
You can simply replace &nbsp; with \xa0 for text messages.

like image 36
oboshto Avatar answered Sep 21 '22 17:09

oboshto