Unable to remove dynamically added content with jQuery
By : Cihan Tunca
Date : March 29 2020, 07:55 AM
I hope this helps . I'm using jQuery to let users dynamically add and remove form fields, but it's not working properly. , Here's how you want to use on code :
$(document).on("click", ".deleteDog", function(e) {
e.preventDefault();
$(this).parent().remove();
});
$("#foo").on("click", ".deleteDog", function(e) {
e.preventDefault();
$(this).parent().remove();
});
$(".deleteDog").on("click", function(e) {
e.preventDefault();
$(this).parent().remove();
});
$(".deleteDog").bind("click", function(e) {
e.preventDefault();
$(this).parent().remove();
});
|
Remove dynamically loaded content with jQuery
By : rda
Date : March 29 2020, 07:55 AM
I hope this helps you . I want to remove some div elements that are added with a wordpress loop via a get_template_part();. , Adjusted Selector Modify the jQuery selector to: code :
<script>
$('#level1 .noPad:gt(1)').remove();
//Or
$(document).find('#level1 .noPad:qt(1)').remove();
</script>
<script>
$('#level1 .noPad').slice(3).remove();
</script>
<script>
$.ajax({
.. //Other Opts
success: function( data ) {
$('#somediv').html( data );
var NodesToRemove = $(document).find('#level1 > div:gt(1)');
//Or $('#somediv').find('#level1 .noPad:qt(1)').remove();
NodesToRemove.remove();
});
});
</script>
$Counter = 0;
if ( have_posts() ) {
while ( have_posts() ) {
$Counter++;
the_post();
if ( $Counter <= 2 )
get_template_part('new-story');
}
}
$Counter = 0;
$isAjax = ( isset( $_GET["ajax"] ) && $_GET["ajax"] == 'true' ? true : false );
if ( have_posts() ) {
while ( have_posts() ) {
$Counter++;
the_post();
if ( !$isAjax || ( $isAjax && $Counter <= 2 ))
get_template_part('new-story');
}
}
|
Can I dynamically generate & remove content from jQuery Accordion before tab is opened and closed?
By : user2453159
Date : March 29 2020, 07:55 AM
I wish this help you Use the beforeActivate and activate methods, as described in the API. code :
beforeActivate: function (event, ui) {
var el = ui.newPanel[0];
if (el) el.innerHTML = returnContent(el.id); // Opening
},
activate: function (event, ui) {
var el = ui.oldPanel[0];
if (el) el.innerHTML = "" // Closing
}
|
Add and remove row dynamically from jquery from given content
By : Maadawan
Date : March 29 2020, 07:55 AM
To fix the issue you can do I tried follows code from refer various site but stuck on add/remove dynamic row. , Here is the modified code: code :
$(document).ready(function() {
$("#button").click(function(e){
e.preventDefault();
var name = $('#name').val();
var gender = $('input:radio[name=sex]:checked').val();
var resident= $('input:checkbox:checked').val();
var education = $("#selectbox").val();
var content = '<td>' + name + '</td>' +
'<td>' + gender + '</td>' +
'<td>' + resident + '</td>' +
'<td>' + education + '</td>' +
'<td><button class="edit-row">Edit</button><button class="delete-row">Delete</button></td>';
if ($(this).hasClass('save-edit')) {
$('.editing').html(content);
$("#button").removeClass('save-edit').val('Submit');
} else {
var rowContent = '<tr class="employee-row">' + content + '</tr>';
$('#empinfo').append(rowContent);
}
});
$('body').on('click', '.edit-row', function (e) {
$('.editing').removeClass('editing');
$(this).closest('.employee-row').addClass('editing');
$("#button").addClass('save-edit').val('Save');
});
$('body').on('click', '.delete-row', function (e) {
$(this).closest('.employee-row').remove();
});
});
|
How to remove dynamically created content in jQuery
By : Bryl Morato
Date : March 29 2020, 07:55 AM
This might help you this is not defined in that scope. If you bind .bind(this) on the function in the onclick attribute, your code will work as expected. code :
$(document.body).on( 'click', '.fcClick', function( event ) {
if( $( this ).attr( 'name' ) == 'fcButtonMinus' ) {
$( this ).closest( '.input-group' ).find( 'input' ).val('');
//$( this ).closest( "div.input-group" ).addClass( "hideContentBlock" );
return false;
}
if( $( this ).attr( 'name' ) == 'fcButtonPlus' ) {
$( 'span#fcAdds' ).append(
'<div class="col-md-10 persStmtPad input-group" style="margin-top:0.125em;margin-left:35px">' +
'<input id="fallCourses" name="fallCourses[]" type="text" placeholder="additional Fall Course" class="form-control input-md">' +
'<div class="input-group-btn">' +
'<button name="fcButtonMinus" class="btn btn-default btn-md" onClick="fcFunc.bind(this)()" style="background-color:#efefef;color:#999;margin-top:12px" title="Delete this Fall Course"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>' +
'</div>' +
'</div>'
);
return false;
}
});
function fcFunc() {
$( this ).closest( "div.input-group" ).addClass( "hideContentBlock" );
return false;
}
div.hideContentBlock {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="col-md-10 persStmtPad input-group" style="margin-top: 1.5em;margin-left:35px">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<input id="fallCourses" name="fallCourses[]" type="text" placeholder="Fall Course" class="form-control input-md" required="" value="testing">
<div class="input-group-btn">
<button name="fcButtonMinus" class="btn btn-default btn-md fcClick" style="background-color:#efefef;color:#999;margin-top:12px" title="Erase this Fall Course" value=""><span class="glyphicon glyphicon-erase" aria-hidden="true"></span></button>
<button name="fcButtonPlus" class="btn btn-default btn-md fcClick" style="background-color:#efefef;color:#999;margin-top:12px" title="Add another Fall Course" value=""><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
</div>
</div><!-- end input-group -->
<span id="fcAdds"></span>
|