How to add space after elements added via jQuery
Posted
by ahsteele
on Stack Overflow
See other posts from Stack Overflow
or by ahsteele
Published on 2010-05-12T23:38:37Z
Indexed on
2010/05/12
23:44 UTC
Read the original article
Hit count: 183
jQuery
I am rendering a similar construct to the below with some server side code. The server side code inserts hard returns in between the project label and text fields. Not a big deal except the below jQuery code inserts the project label and text fields mashed together.
var projectLabel = $('<label for="project">Project</label>');
var projectField = $('<input type="text" name="project" id="projectName" />');
projectLabel.insertBefore($(this));
projectField.insertBefore($(this));
Because of this discrepancy the elements rendered server side have a space between them while the ones rendered on the client do not. I've tried adding a nbsp;
at the end of each line to no avail. Unfortunately, I have been unable to remove the hard returns outputted by the server side code. Further because of the space I can't fix this with CSS. What are my options for adding spacing via jQuery?
© Stack Overflow or respective owner