0

This code:

$('.grid-stack').on('resizestop', function(e) {
        var element = e.target;
        console.log(element);
 });

outputs:

<div class="grid-stack-item ui-draggable ui-resizable ui-resizable-autohide" data-gs-x="0" data-gs-y="2" data-gs-width="7" data-gs-height="2">
                <div class="grid-stack-item-content ui-draggable-handle">
                    <div class="box-prop top-widget" data-sortable-id="cars-sold-minute" id="cars-sold-minute-block">
                        <i class="fa fa-times close-x" aria-hidden="true" style="display: none;"></i>
                        <div class="single-pie">

To the console.log. I am attempting to get the id which is cars-sold-minute-block using jquery but have not been successful. How do I get the id when using the event target?

Edit: I don't want to name the id, as this will be for many different elements.

2 Answers2

0

You can get it by the element class

 $('.grid-stack').on('resizestop', function(e) {
        var element = e.target;
        var id = $(element).find('.box-prop.top-widget').attr('id');
        console.log(element);
 });
Kld
  • 6,970
  • 3
  • 37
  • 50
0

For More performance, use $ with two arguments where the 2nd argument is the CTX (parent) :

 $('.grid-stack').on('resizestop', (e)=> {
        let element = e.target;
        var id = $('.box-prop.top-widget',element).attr('id');
        console.log(id);
 });
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254