-3

I'm trying to format a content (text) of a td element using JavaScript. However, the element does not have an ID property (to use getElementbyID) and has a non-unique Class property (to use getElementbyClass).

I have no control over the html part, to change the Class name or include an ID property. All that is constant is the text within the <td>.

Any idea how I can write a script that will format (say, make the text bold?)?

Note that I cannot use JQuery.

<table width="100%" class="ms-formtable" style="margin-top: 8px;" border="0" cellspacing="0" cellpadding="0">
  <tbody>
    <tr>
      <td width="90%" class="ms-formlabel" valign="top">
        General
      </td>
    </tr>
  </tbody>
</table>
kukkuz
  • 41,512
  • 6
  • 59
  • 95
tempidope
  • 823
  • 1
  • 12
  • 29

1 Answers1

-1

you can select the first element and change the style of it with .style

var elem = document.querySelectorAll('td.ms-formlabel')[0];
elem.style.fontWeight = "900";
<table width="100%" class="ms-formtable" style="margin-top: 8px;" border="0" cellspacing="0" cellpadding="0"> 
        <tbody><tr>
        <td width="90%" class="ms-formlabel" valign="top">
        General
        </td>
        </tr>
        </tbody></table>
iHasCodeForU
  • 179
  • 11
  • This works only if the element with the given class is the first *and* only element with that class-name; as the question makes clear that the element has a non-unique class-name that can't necessarily be guaranteed. Admittedly this question would benefit greatly from a less-simplified [mcve]. – David Thomas Dec 16 '16 at 14:53