Jacs
Jacs

Reputation: 1537

How to get id of div using jquery?

{"__reactInternalInstance$scd8ef5s9":{"tag":5,"key":null,"elementType":"div","type":"div","stateNode":"~","return":{"tag":5,"key":null,"elementType":"div","type":"div","stateNode":{"__reactInternalInstance$scd8ef5s9":"~__reactInternalInstance$scd8ef5s9~return","__reactEventHandlers$scd8ef5s9":{"id":0,"style":{"position":"absolute","zIndex":0,"display":"flex","justifyContent":"center","alignItems":"center","width":100,"height":100,"backgroundColor":"white"},"className":"box resizable","children":[{"type":"div","key":null,"ref":null,"props": "props..." ......

console.log(CircularJSON.stringify($(this).find("div")[0]));

Prints it.

Here is the html:

  <div
    className="myClass"
  >
    <div
      className="resizerClass"
      id="tomatoes"
       >
        <div className="resizers">
        </div>
      </div>
      <div className="resizers"></div>
  </div>

I need the id os resizerClass div? how to get it?

Upvotes: 2

Views: 631

Answers (1)

Raeesh Alam
Raeesh Alam

Reputation: 3480

If you want to find ID by jQuery as your HTML attributes(className) then you can define attribute in square bracket like $('[className="resizerClass"]') and get other attributes value like attr('id').

$(document).ready(function(){
  var getId = $('[className="resizerClass"]').attr('id');
  console.log('id='+getId);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div className="myClass">
  <div className="resizerClass" id="tomatoes">
    <div className="resizers"></div>
  </div>
  <div className="resizers"></div>
</div>

Upvotes: 4

Related Questions