Andrew Spackman
asked on
Cannot read property 'replace' of undefined when trying to remove html using jQuery
I have 4 pipes that I'm trying to remove using jQuery, but when I use the script below, it seems to throw an error in the console "cannot read property 'replace' of undefined"
Can someone help me with removing this error please?
jQuery(document).ready(function($) {
$('div.dokan-product-listing.dokan-product-listing-area.row-actions').html($('div.dokan-product-listing.dokan-product-listing-area.row-actions').html().replace('|',''));
$('div.dokan-product-listing.dokan-product-listing-area.row-actions').html($('div.dokan-product-listing.dokan-product-listing-area.row-actions').html().replace('|',''));
$('div.dokan-product-listing.dokan-product-listing-area.row-actions').html($('div.dokan-product-listing.dokan-product-listing-area.row-actions').html().replace('|',''));
$('div.dokan-product-listing.dokan-product-listing-area.row-actions').html($('div.dokan-product-listing.dokan-product-listing-area.row-actions').html().replace('|',''));
});
Can someone help me with removing this error please?
ASKER
I am getting an error with this, v exists but is never defined?
I don't use "v" in my code...
You can remove i,v
You can remove i,v
ASKER
Ok, so this is now what I am using, I am not getting any errors in my console but it's not removing the pipe symbols
jQuery(function($) {
$('div.dokan-product-listing.dokan-product-listing-area.row-actions').each(function() {
var html = $(this).html(); // get HTML content
html.replace('|','');
$(this).html(html);
});
});
what do you get in the alert ? also please share a page to see it in live
jQuery(function($) {
alert( $('div.dokan-product-listing.dokan-product-listing-area.row-actions').length );
$('div.dokan-product-listing.dokan-product-listing-area.row-actions').each(function() {
var html = $(this).html(); // get HTML content
html.replace('|','');
$(this).html(html);
});
});
ASKER
I get the value "1" appear in a popup?
Here is the page I am having issues with but its a restricted page to vendors only
Here is the page I am having issues with but its a restricted page to vendors only
Ok, could you copy/paste what you get in the textarea (dynamically added at the top of the page w/ the following) :
jQuery(function($) {
$('div.dokan-product-listing.dokan-product-listing-area.row-actions').each(function() {
var html = $(this).html(); // get HTML content
$("<textarea/>").val(html).prependTo("body");
html.replace('|','');
$(this).html(html);
});
});
ASKER
This is what I get
<div class="container p-0 row-actions">
<div class="col col-sm-4 p-0 clearfix align-items-stretch">
<span class="col-6 w-50 float-left d-inline-block btn-vendor-primary btn-vendor-edit"><a href="https://www.ingeniousgifts.co.uk/dashboard/products/?product_id=1248&action=edit">Edit Gift</a></span> | <span class="col-6 w-50 float-left d-inline-block btn-vendor-primary btn-vendor-delete"><a href="https://www.ingeniousgifts.co.uk/dashboard/products/?action=dokan-delete-product&product_id=1248&_wpnonce=9e3b08a475" onclick="return confirm( 'Are you sure?' );">Remove</a></span> | <span class="col-6 w-50 float-left d-inline-block view"><a href="https://www.ingeniousgifts.co.uk/?post_type=product&p=1248">View Gift</a></span> | <span class="item-inline-edit"><a href="#quick-edit" data-product-id="1248">Quick Edit</a></span> | <span class="duplicate"><a href="https://www.ingeniousgifts.co.uk/dashboard/products/?action=dokan-duplicate-product&product_id=1248&_wpnonce=a35a2a7ce5">Duplicate</a></span> </div>
</div>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi leakim971,
This worked a treat, thank you very much for your help.
This worked a treat, thank you very much for your help.
Open in new window