1

I am trying to get the ID property hanging off the getElementById method however it seems to return null or undefined. I have checked my HTML and it does in fact have an ID associated with it. I have given all my columns different ID's so having mulitple occurrences of the same ID is not the problem.

var columnID = $(this).closest(".col-md-4.column").id;
console.log(columnID);
var column = document.getElementById(columnID);

 <div class="row" id="columns">
<div class="col-md-4 column" id="col1">
    <div class="panel panel-default" draggable="true">
        <div class="panel-heading">
            <h3 class="panel-title">
                Panel title
                <span class="glyphicon glyphicon-pencil panel-icons"></span>
                <span class="glyphicon glyphicon-zoom-in panel-icons"></span>
                <span class="glyphicon glyphicon-trash panel-icons"></span>
            </h3>
        </div>
        <div class="panel-body" id="testchart">
            CHART GOES HERE
        </div>
    </div>

    <div class="panel panel-default" draggable="true">
        <div class="panel-heading">
            <h3 class="panel-title">
                Panel title
                <span class="glyphicon glyphicon-pencil panel-icons"></span>
                <span class="glyphicon glyphicon-zoom-in panel-icons"></span>
                <span class="glyphicon glyphicon-trash panel-icons"></span>
            </h3>
        </div>
        <div class="panel-body">
            World
        </div>
    </div>

    <div class="panel panel-default" draggable="true">
        <div class="panel-heading">
            <h3 class="panel-title">
                Panel title
                <span class="glyphicon glyphicon-pencil panel-icons"></span>
                <span class="glyphicon glyphicon-zoom-in panel-icons"></span>
                <span class="glyphicon glyphicon-trash panel-icons"></span>
            </h3>
        </div>
        <div class="panel-body">
            Hello
        </div>
    </div>
</div>
<div class="col-md-4 column" id="col2">

</div>
<div class="col-md-4 column" id="col3">
Johnathon64
  • 1,280
  • 1
  • 20
  • 45

3 Answers3

4

Try this:

var columnID = $(this).closest(".col-md-4.column").attr('id');
Prasanna
  • 779
  • 5
  • 13
1

There is no id property. Use .attr('id').

Armand
  • 23,463
  • 20
  • 90
  • 119
0

Try

$(this).closest(".col-md-4.column").attr('id')

The attributes have to be accessed with the .attr method

George
  • 6,630
  • 2
  • 29
  • 36