Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append a space with jQuery

Tags:

I'm trying to append a space using jQuery. Neither of these samples work:

   $("#mySelector").append($(" "));   $("#mySelector").append($(" ")); 

Any ideas?

like image 941
Joel Harris Avatar asked Sep 30 '09 22:09

Joel Harris


People also ask

How to give space in JQuery?

You could also use '\xa0', it is a non break space character. Show activity on this post. And, create a JQuery Plugin function to reuse it whenever you need to put space. This way you will be consistent throughout.

How to add space in javascript?

Use the padEnd() and padStart() methods to add spaces to the end or beginning of a string, e.g. str. padEnd(6, ' '); . The methods take the maximum length of the new string and the fill string and return the padded string. Copied!

How to give space between text in javascript?

To add a space between the characters of a string, call the split() method on the string to get an array of characters, and call the join() method on the array to join the substrings with a space separator, e.g. str. split('').

How to add space between variables in javascript?

To add two strings we need a '+' operator to create some space between the strings, but when the first string itself has a space with in it, there is no need to assign space explicitly.


2 Answers

How about

$("#mySelector").append(" "); // or with & nbsp; 
like image 165
Ólafur Waage Avatar answered Sep 27 '22 17:09

Ólafur Waage


In my case I did the following:

$('.colwid10a').each(function () {     if ($(this).is(':empty')) {         $(this).append(" ");     } }); $('.colwid12').each(function () {     if ($(this).find('a').is(':empty')) {         $(this).find('a').append(" ");     } }); 
like image 42
Jatinder Avatar answered Sep 27 '22 17:09

Jatinder