Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery do something after DOM element is created - DOMNodeInserted not working

Ok, I have one empty div, which is dynamically filled with some content later:

<div class="row no-margin">
    <div id="sensorInfoContent">
    </div>
</div>

Later it is filled with some other divs and content. I need to select this child div:

<div class="circDash" id="batPerc" accesskey="30" style="height:100px; background-color:#000000;">

And call this function on it:

$(*DIV*).circleProgress({
            value: 0.75,
            size: 80,
            fill: {
                gradient: ["red", "orange"]
           }
        });

I tried to do that on click, and it's working. Like this:

$('#sensorInfoContent').on("click", ".circDash", function() {

    $(this).circleProgress({
        value: 0.75,
        size: 80,
        fill: {
            gradient: ["red", "orange"]
       }
    });
});

But I need it to be done after element is dynamically added, not on click. Tried DOMNodeInserted, it's not working:

    $('#sensorInfoContent').on("DOMNodeInserted", ".circDash", function() {

        $(this).circleProgress({
            value:

 0.75,
        size: 80,
        fill: {
            gradient: ["red", "orange"]
       }
    });
}); 

Any ideas, alternatives or work-arounds?

like image 697
Tinmar Avatar asked Apr 24 '26 06:04

Tinmar


1 Answers

Just trigger the click manually

$('#sensorInfoContent').on("click", ".circDash", function() {

    $(this).circleProgress({
        value: 0.75,
        size: 80,
        fill: {
            gradient: ["red", "orange"]
       }
    });
});

Like this

$('.circDash').trigger('click');
like image 141
Sudharsan S Avatar answered Apr 26 '26 19:04

Sudharsan S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!