javascript - Spacing different in original html rendering vs dynamic JS rendering -
here small part of page:
<a href="#" onclick="policyviolation(<%: viewbag.devicedata[i].deviceid%>); return false;"> <span class="policyviolationsnumber"><%= viewbag.devicedata[i].violationcount%></span> <span>policy violations</span> </a> this renders out have space between 2 spans.
in code, update in js:
var spanviolationnumber = $('<span>') .html(statusmodel.violations) .addclass('policyviolationsnumber'); var spanviolationstring = $('<span>') .html('<%=servicesite.resources.resources.devices_policy_violations%>'); var imagetag = $('<img>') .attr('src', '/content/images/error_error.png') .attr('align', 'absmiddle'); var anchortag = $('<a href="#">') .append(spanviolationnumber) .append(spanviolationstring); cell.empty(); cell.append(imagetag) .append(anchortag); however, renders out no space between spans. i've seen small issues before never figured out is. can ignore image tag stuff, irrelevant.
edit:
didn't know this, guess it's expected behaivor: http://jsfiddle.net/2mmua/
the space happening because of way formatting html.
the "span" tag inline html element. means need treat treat text on page.
<span>hello</span> <span>world</span> <!-- prints hello world --> <span>hello</span> <span>world</span> <!-- prints hello world line break space coming from. --> <span>hello</span><span>world</span> <!-- prints helloworld how ".append()" function formatting html. adds literally right after last character in html. --> in order normalize across 2 different techniques, either have butt "span" tags right next each other html doesn't add space...
<span></span><span></span> ..or need manually add space in ".append()" function.
obj.append(' ' + spantag); i hope helps!
Comments
Post a Comment