- Mar 22, 2013
- 8,692
- 10,261
We have this HTML on a page which appears after I do a few clicks (not on pageload):
I want to change the "AM" to "PM" using Greasemonkey. I tried one method, and while I could see the change in the text box, it wasn't actually "recorded" by the site.
Then I found another method which works, except it breaks the entire site and I can't click anything else on the site after running the code:
I found this code here (I edited it slightly using one of the replies to make it work) - https://stackoverflow.com/questions/1155353/find-and-replace-in-a-webpage-using-javascript
One of the guys gave this reply:
Modifying innerHTML, which inculdes each element's children, is a very bad advice because it'll break lots/most of pages that use addEventListener and element references.
I think this is my problem. When I run the code, it makes the change I want, but it breaks the site.
Can anyone help? Thanks
HTML:
<input class="form-control" value="07/01/2022 12:00 AM" type="text">
I want to change the "AM" to "PM" using Greasemonkey. I tried one method, and while I could see the change in the text box, it wasn't actually "recorded" by the site.
Then I found another method which works, except it breaks the entire site and I can't click anything else on the site after running the code:
JavaScript:
var els = document.getElementsByClassName("form-control");
for(var i = 0, l = els.length; i < l; i++) {
var el = els[i];
document.body.innerHTML = document.body.innerHTML.replace(/AM/gi, 'PM');
}
I found this code here (I edited it slightly using one of the replies to make it work) - https://stackoverflow.com/questions/1155353/find-and-replace-in-a-webpage-using-javascript
One of the guys gave this reply:
Modifying innerHTML, which inculdes each element's children, is a very bad advice because it'll break lots/most of pages that use addEventListener and element references.
I think this is my problem. When I run the code, it makes the change I want, but it breaks the site.
Can anyone help? Thanks