1

I have html like below

<span id="3072" style="position: relative; display: inline-block; width: 1898px; height: 194px; ">
     <div style="visibility: visible; text-align: center; position: absolute; top: 90.5px; width: 1898px;">
         <div style="font-family: Arial; font-size: 8.25pt; font-style: normal;>
         </div>
     </div>
</span>

here I want to change font-size:8.25pt to 14pt from the last div tag, how do I access contents of the last div tag using id from span tag.

I can easily change the contents of the 1st div tag something like below

document.getElementById("3072").firstChild.fontize="14px";

But in this case the Div tags doesn't have any classes or Id's to access them.

Anyone has any thoughts on this please share.

Image attached which shows the code of the html.

Thanks.

Marcs
  • 3,768
  • 5
  • 33
  • 42
rahulS
  • 13
  • 5

1 Answers1

1

The easiest way is to add a class or id directly to your target element, but if you can not change the markup then you can use:-

use querySelector

document.querySelector('[id="3072"]>div>div').style['font-size'] = '14px';
<span id="3072" style="position: relative; display: inline-block; width: 1898px; height: 194px; ">
     <div style="visibility: visible; text-align: center; position: absolute; top: 90.5px; width: 1898px;">
         <div style="font-family: Arial; font-size: 8.25pt; font-style: normal;">
           14px
         </div>
     </div>
</span>

or jQuery

$('#3072>div>div').css('font-size', '14px');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="3072" style="position: relative; display: inline-block; width: 1898px; height: 194px; ">
  <div style="visibility: visible; text-align: center; position: absolute; top: 90.5px; width: 1898px;">
    <div style="font-family: Arial; font-size: 8.25pt; font-style: normal;">
      14px
    </div>
  </div>
</span>

Note: see here about using numbers as id's.

Community
  • 1
  • 1
BenG
  • 14,826
  • 5
  • 45
  • 60