Search code examples
javascriptjqueryhtmlsharepoint-2010

Fetch a div via jQuery in SharePoint site


In a sharepoint site I have the following div that I need to call it. Problem is in SP sites the id is dynamic and it is bad idea to use, but I don't know any other way to call the div? Any suggestion?

<span dir="none">
<div class='ms-rtestate-field ms-rtefield' style=''>
<div id='_ctl00_TextField_inplacerte_label' style='display:none'>Rich text 
editor no & (Title)</div>
 <div class=' ms-rtestate-write ms-rteflags-0' 
 id='_ctl00_TextField_inplacerte' style='min-height:42px' aria-
  labelledby='_TextField_inplacerte_label'  contentEditable='true' >
 <div class="ms-rtestate-field"> no & (Title) field value.
  </div>
  </div>
  <div style="clear:both;"></div></div>
<span dir="ltr">

Solution

  • Try with below line.You can get same also from class name

    var divId = $('.ms-rtestate-write').attr('id');
    console.log(divId);
    

    Now you can do whatever you want with this Id or you can do same manipulation from class also.

    let me know if it solve your problem.If you have multiple parrallel div with this div then let me know i will share it.