jQuery xmlns=“…” attribute causing formatting problems in Chrome

96
January 01, 2020, at 5:40 PM

I am using jQuery to dynamically build a table of items. Below is a simplified version of the code that reproduces the issue I am running into. Iterating a simple JSON object, I attempt to add a row for each item within the item div using jQuery's append() method.

JSON:

var menuTemplate = [
    {
        "label":"First Item",
    },
    {
        "label":"Second Item",
    }
];

JavaScript:

function createMenu() {
    $.each(menuTemplate, function(index, item){
        var row = $('<div class="row"></div>');
        var label = $('<div class="col-sm">' + item['label'] + '</div>');
        row.append(label);
        $('#menu').append(row);
    });
}

HTML:

<body style="background:#ffffff">
    <div id="menu" class="container"></div>
</body>

The resultant output is mostly correct, however it contains some xmlns attributes on some elements that cause layout problems in Chrome:

<div xmlns="http://www.w3.org/1999/xhtml" id="menu" class="container">
    <div xmlns="" class="row">
        <div class="col-sm">First Item</div>
    </div>
    <div xmlns="" class="row">
        <div class="col-sm">Second Item</div>
    </div>
</div>

Firefox and Edge don't seem to have issues displaying the content, but in Chrome, "First Item" and "Second Item" display on the same row with no space in between, as follows:

First ItemSecond Item

whereas in Firefox and Edge, they are correctly displayed on their own lines as:

First Item

Second Item

My question is, Why is the formatting lost with the addition of the xmlns attribute?, and perhaps more essentially, How do I prevent the xmlns attribute from being added in the first place?

EDIT: This is what the generated source looks like from the view of the document inspector after the above JavaScript is run on document load:

READ ALSO
Refresh main window without closing popup in html

Refresh main window without closing popup in html

I need to refresh a html page while the popup is still open, I am using a jsp page with spring mvc is there any way to refresh the parent page while the popup is still open? The same question was asked in thisthread but the answer does not workIs this achievable?

89
Summernote callbacks onPaste function giving errors

Summernote callbacks onPaste function giving errors

I'm using summerNote as an HTML editor to write contents in front endI was a bit concerned about copy pasted contents so I used callBacks logic in which I used onPaste event

98
Having issue using jquery to create link tags and concatenate the href attribute to store a reult variable

Having issue using jquery to create link tags and concatenate the href attribute to store a reult variable

To do so, I created a variable named link to store the link's info as follows:

88
jQuery html method behave strangely inside userScript

jQuery html method behave strangely inside userScript

I have the following line inside a userScript:

111