I'm trying to append a space using jQuery. Neither of these samples work:
$("#mySelector").append($(" ")); $("#mySelector").append($(" "));
Any ideas?
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.
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!
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('').
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.
How about
$("#mySelector").append(" "); // or with & nbsp;
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(" "); } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With