isbe
isbe

Reputation: 253

How to remove value of the class in an existing code (wordpress)?

I need to remove 'mylogin' that is inside the class.
I tried the folloing code but it doesn't remove 'mylogin'.
Would you please let me know how to remove it?

Existing code:

<div class="elementor-column elementor-element-84c7af1 mylogin" data-id="84c7af1" 
data-element_type="column" id="my-checkout">

I tried:
<?php
 echo '<script>';
 echo 'function myFunction() { var element = document.getElementById("my-checkout"); ';
 echo 'element.classList.remove("mylogin");}'; 
 echo '</script>';

Thank you.

Upvotes: 0

Views: 64

Answers (1)

Jay Hewitt
Jay Hewitt

Reputation: 1126

You need something to execute the JS function you've created. Wrapping in brackets and then executing using the brackets after is how it will be fired.

e.g.

function(){ alert("I won't do anything until requested"); }

(function(){ alert("I get fired immediately"); })();

Below will add the JS block IF the current url/slug contains my-pay.

$removeMyLoginJs = <<<EOD
<script>
    (function myFunction() {
        var element = document.getElementById("my-checkout");
        element.classList.remove("mylogin");
    })();
</script>
EOD;

global $wp;
$currentSlug = add_query_arg([], $wp->request);

if(strpos($currentSlug, "my-pay") !== false){
    echo $removeMyLoginJs;
}

Upvotes: 1

Related Questions