Would regex be the solution for this? I have other pieces of code i also need to generate and is too crazy to copy and paste/edit manually. I wanted to start with this one and learn on by myself.
I’m not sure what you are asking. Regular expressions are typically used to match patterns, not to generate text. Could you explain what you’re trying to do in more detail?
Im no expert but as @ArielLeslie said , regex are primarily used to match or filter out patterns and not create stuff like divs.
It will work but it depends on how you write it. I cant give you any samples since I hv no idea what project you are doing. From the information you hv given , u dont need to write over the divs, you can use += operator to append more divs using javascript innerHTML.
Again, im not sure what kind of case you are dealing with so take this with a grain of salt.
Without seeing your project, it is hard to offer specific advice, but there are a number of ways that you could programatically create some divs while hardcoding others.
If you’re going to be doing a lot of programatic DOM manipulation, you also might want to consider using a framework like React, Angular, or Vue.
Can you elaborate what you meant by manually edited?
Are they divs you wrote in html or by some other way?
Yep . If you are familiar with frameworks or libraries you might be able to find a way to deal with your situation, maybe.
Edit: if you mean manually edited images in the divs which you must edit later, you can access the ids of the divs generated by storing them and then change the image property .
I’m currently writing them by hand (and a little copy pasting where possible)
But I kind of need the divs (div1 to div1000 ) to have hardcoded number that increment per div. This for the class, the figcaption text and the image.png (001.png - 1000.png)
Don’t think js or DOM action will create this hard-coded code.
BTW, if you try looping 3500 times using your current code it will block the browser. When I tested it ran out of memory and crashed (Edit: I was testing it with invalid file paths so that might also have contributed).
If you switch to insertAdjacentHTML it works, but it’s still pretty resource-intensive code.