JavaScript Capitalize first letter of various tags content element capitalize first letter javascript,capitalize first letter python,capitalize first

I need to capitalize the first letter of various html elements such as p, h2, h3, h4.

This stack question has helped me, however, it only targets the p tag. How can I say to target more than one tag?

Such as:

function change(charm) {
   var string = eval(charm).toLowerCase(), change = "", newstring = string.split("."),   tochange;
   for (var i = 0; i < newstring.length; i++) {
       tochange = newstring[i].trim().charAt(0);
       newstring[i] = newstring[i].replace(tochange, tochange.toUpperCase());
}
   change = newstring.join(" . ");
   return change;
}

var text = change("document.getElementsByTagName('p, h2, h3, h4')[0].innerHTML");
document.getElementsByTagName("p, h2, h3, h4")[0].innerHTML = text;

That doesn't work, am I doing something wrong with targetting various elements?

Answer:1

HTML: <select id="mySelect"> <option>Apple</option> <option>Orange</option> <option>Pineapple</option> <option>Banana</option> &...

HTML: <select id="mySelect"> <option>Apple</option> <option>Orange</option> <option>Pineapple</option> <option>Banana</option> &...

  1. javascript item method

So let's say we have the following XML structure: <property> <label>Label 1</label> <value>value 1</label> </property> <property> <label>...

So let's say we have the following XML structure: <property> <label>Label 1</label> <value>value 1</label> </property> <property> <label>...

  1. can getelementsbytagname return null
  2. what does getelementsbytagname return
  3. what does document getelementsbytagname return

I had a simple script working using Promises in ECMA6 but I'm now converting what I wrote to jQuery to be compatible for all browsers but the issue I'm having is that availableDevices contains an ...

I had a simple script working using Promises in ECMA6 but I'm now converting what I wrote to jQuery to be compatible for all browsers but the issue I'm having is that availableDevices contains an ...

  1. jquery function after page load
  2. jquery function after delay
  3. jquery function after load
  4. jquery function after function complete
  5. jquery function after .each() has completed
  6. jquery function after function
  7. jquery function after animate
  8. jquery function after append
  9. jquery function after fadeout
  10. jquery function after another
  11. jquery function after timeout
  12. jquery function after time
  13. jquery function after ajax load
  14. jquery function after click event
  15. jquery function after page load complete
  16. jquery function after click
  17. jquery function after load html
  18. jquery function after dom load
  19. jquery function after submit
  20. jquery function after addclass

My application uses iframes to display content. I need to detect whether a page is loaded in an iframe. The problem is I need to do it with php, javascript manipulation of the DOM is not enough, I ...

My application uses iframes to display content. I need to detect whether a page is loaded in an iframe. The problem is I need to do it with php, javascript manipulation of the DOM is not enough, I ...