It seems there is no problem with your code, mostlikely its because you try to delete the content before the dom is ready.
You can check my working example below
EDIT----
I have tried using dynamic inserted content, its works fine too. Please check if there is any error logged in your browser console log
Regarding data-role flipswitch, thats the identifier that trigger flipswitch js
$(document).ready(function(){
$("#content").append('<div id="btn_flip3">lorem ipsum dolor sit amet consectuer adisplicing elit</div>').trigger('create');
$("#js-delete").on('click', function($evt){
$evt.preventDefault();
$("#btn_flip3").html("content deleted");
});
});
#content{ margin-bottom:20px; }
.control-box{
padding:20px;
background:#eee;
border:#ddd solid 1px;
}
#js-delete{
background:red;
color:#fff;
display: inline-block;
padding:4px 8px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="content"></div>
<div class="control-box"><a id="js-delete">Delete Dynamic Content</a></div>
Answer from ilmansg on Stack OverflowJquery: create empty object to work with
text1
'); $bar=$bar.add('text2
'); $foo.append($bar); Note: Just running .add() on an object does not change that object, just adds to the current "chain". To make it permanent you need to assign the new "chain" to the original variable. More on reddit.comJQuery .empty(), .remove() or .html('')
How to create an empty JQuery element and populate it?
Differentiating between 0 and empty field with parseFloat.
Videos
Can please someone explain to me why this does not work:
http://jsfiddle.net/nipheon/kKj7L/
I have been google-ing for the past half hour and all I find are stackoverflow posts telling me this should work... :(
text1
'); $bar=$bar.add('text2
'); $foo.append($bar); Note: Just running .add() on an object does not change that object, just adds to the current "chain". To make it permanent you need to assign the new "chain" to the original variable.It seems there is no problem with your code, mostlikely its because you try to delete the content before the dom is ready.
You can check my working example below
EDIT----
I have tried using dynamic inserted content, its works fine too. Please check if there is any error logged in your browser console log
Regarding data-role flipswitch, thats the identifier that trigger flipswitch js
$(document).ready(function(){
$("#content").append('<div id="btn_flip3">lorem ipsum dolor sit amet consectuer adisplicing elit</div>').trigger('create');
$("#js-delete").on('click', function($evt){
$evt.preventDefault();
$("#btn_flip3").html("content deleted");
});
});
#content{ margin-bottom:20px; }
.control-box{
padding:20px;
background:#eee;
border:#ddd solid 1px;
}
#js-delete{
background:red;
color:#fff;
display: inline-block;
padding:4px 8px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="content"></div>
<div class="control-box"><a id="js-delete">Delete Dynamic Content</a></div>
try my edited answer :
$('.my_class').next('div').remove();
$('.my_class').remove();
You should create form element like this $('<form>) and then you can use append method.
const forms_data = ['Name', 'Email'];
const form = $('<form>');
forms_data.forEach(name => {
form.append($('<input>', {placeholder: name}))
})
$('body').append(form);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Update: You could use reduce to make array of inputs or jquery objects and then append that array to form element at once.
const forms_data = ['Name', 'Email'];
const inputs = forms_data.reduce((r, name) => {
r.push($('<input>', {placeholder: name}))
return r;
}, [])
$('form').append(inputs)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action=""></form>
If all you are trying to do is create the inputs and append them to the form, you can use a simple array, or map the elements. $.map can be used to loop over an array, create new elements, and return them as a list at the end. Using this we can create the array, and then append them all at once to the form.
const forms_data = ['Name', 'Email'];
$('form').append($.map(forms_data, function(element){
return `<input placeholder="${element}" / >`;
}));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form></form>