I’m trying to remove a specific tag from array that has a specific value from a WordPress Woo commerce site. When I run the code in Stackoverflows code snippet the jquery executes and works as expected, but on the site it does not execute. What’s even more confusing it that if I paste the jquery into the browser > inspector > console it also executes and deletes the desired tag with the desired value.
CMS: WORDPRESS – Theme: DIVI | page builder: Elementor
CRM: Woo Commerce
jQuery(document).ready(function($) {
if(window.location.href.indexOf("1850-aprilaire-test-progressive") >= 0) {
$('#dehumidifier-hanger-size option[value="Large (Fits 1870 model)"]').remove();
alert('AWESOME jquery is WORKING');
};
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<select id="dehumidifier-hanger-size" class="" name="wccp_attribute_dehumidifier-hanger-size[1597339203]" data-attribute_name="attribute_dehumidifier-hanger-size" data-show_option_none="yes">
<option value="">Choose an option</option>
<option value="Regular (Fits 1820,1830,1850 models)" class="attached enabled">Regular (Fits 1820,1830,1850 models)</option>
<option value="Large (Fits 1870 model)" class="attached enabled">Large (Fits 1870 model)</option>
</select>
4
Answers
@twisted @vmank Using a $('#id').on('load', function - to delete desired option. executes in console, but can't find desired object. returns as undefined. Obviously the entire line 2 is in the wrong place even though the code syntax in correct. can either of you help?
I would try something a bit more loose. Maybe you’re being too specific.
If you see
undefined
in console, then you missed the selection. If you see<option...
you hit the right thing.Have you tried something like this? Using a
load
event handler in most of the cases solves the problem because probably this field is created after theready
event, hence you see the selector working through the console but not inside yourready
handler.@twisted @vmank So, GOOD NEWS!!! Got the jquery to work on Chrome/FF/IE/OPR!!!! BAD NEWS: Doesn’t work on Safari. Can either of you point me in the right direction?
BTW, thanks for all your help. REALLY appreciate it!!!