I'm trying to make a button like this using jQuery/JS
This button is generated using server side rails helper.While inspecting this element I got this
For this I wrote the following code
var editLink = makeElement('a', {
class: 'edit-merchant-url btn btn-primary',
href: url.BASE_MERCHANT_URLS + data.id + url.EDIT,
innerHTML: 'Edit'
});
var editInnerSpan = makeElement('span', {class: 'fa fa-pencil-square-o'});
editLink.appendChild(editInnerSpan);
/**
* It creates the dynamic DOM element
* element should be tag name such as div, input, form
* options should be attributes including class, id, innerHTML
*/
function makeElement(element, options) {
var $formField = document.createElement(element);
$.each(options, function (key, value) {
if (key === 'innerHTML') {
$formField.innerHTML = value;
}
else {
$formField.setAttribute(key, value);
}
});
return $formField;
}
But this create button like
and while inspecting this I got this.
I don't know what I'm doing wrong.
应该:
editLink.prependChild(editInnerSpan)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.