PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 14, 2022

[FIXED] How to remove data-0 attribute from div?

 July 14, 2022     html, jquery, web-deployment     No comments   

Issue

I have a html code like below.

<div id="asa" class="bg"
    data-0="transform:scale(1, 1); opacity:1"
    data-1000="transform:scale(2, 1); opacity:0.5"
    data-5000="transform:scale(2, 2); opacity:1">   

    //Some Code

</div>

I want to remove 'data-1000' attribute from the div or change 'data-1000' into 'data-2500'. How can I do it? I tried $('#asa').removeAttr('data-1000'); and many more. But they did not work.


Solution

Option 1: Try this code first:

document.getElementById('home_bg1').removeAttribute('data-1000');

Option 2: If the first code doesn't work for you ... try this one

If the element you want to edit is loaded by another script, it is necessary for the editing script to wait. This code waits for an item with the ID #home_bg1 to appear and then executes

var checkEx = setInterval(function () {
    var el = document.getElementById('home_bg1');
    if (el) {
        el.removeAttribute('data-1000');
        clearInterval(checkEx);
    }
}, 100);

Option 3: Waiting for an element to appear in the code that has an attribute named "data-1000" and only then is it executed.

If the element you want to edit is loaded by another script and this script is delayed by setting the "datа" values. Then we have to wait for the "data" attribute to appear and then run the script

    var checkEx = setInterval(function () {
        var el = document.querySelector('[data-1000]');
        if (el) {
            el.removeAttribute('data-1000');
            clearInterval(checkEx);
        }
    }, 100);

Example: Put this script before skrollr.min.js

....

<script>
    document.getElementById('home_bg1').removeAttribute('data-1000');
</script>


<script src="skrollr.min.js"></script>
<script>skrollr.init();</script>

....


Answered By - 54ka
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing