Link to home
Start Free TrialLog in
Avatar of Andrew Spackman
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"
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('|',''));
});

Open in new window


Can someone help me with removing this error please?
Avatar of leakim971
leakim971
Flag of Guadeloupe image

try this :
    jQuery(function($) {
        $('div.dokan-product-listing.dokan-product-listing-area.row-actions').each(function(i,v) {
           var html = $(this).html(); // get HTML content
           html.replace('|','');
           $(this).html(html);
        });
    });

Open in new window

Avatar of Andrew Spackman
Andrew Spackman

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
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);
        });
    });

Open in new window

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);
        });
    });

Open in new window

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
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);
        });
    });

Open in new window

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&amp;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&amp;product_id=1248&amp;_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&amp;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&amp;product_id=1248&amp;_wpnonce=a35a2a7ce5">Duplicate</a></span>	</div>
</div>
 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi leakim971,

This worked a treat, thank you very much for your help.