How to insert a customized button back into HTML via javascript?

<p id="button">

That’s what my paragraph looks like, the idea is when x reaches a certain point to insert a customized button there.

function ran() {
if (x==1) {
document.getElementById("button").innerHTML="<button onclick=""> Reset </button>";

So there’s my script, when I use just " Example it works fine but as soon as I try to customize it with “onclick” it won’t work. Another thing I was wondering was how you would use javascript to insert something (+=) into a certain part of a certain div/paragraph/etc instead of just adding it to the very end of that area.

How are you referencing the script when you set use the onclick attribute and what are the script contents? From what I know the HTML Event Handlers (attaching an onclick attribute to run a function) aren’t used anymore. I would look into writing an external script as a DOM Level 2 or Traditional Event Handler. If you have questions about that let me know.

For inserting content into a div/para/etc. There are various string methods you can use, depending on how you want to add the content. You can use methods such as indexOf, charAt, split - with the element selected beforehand. It all depends on specifically what you want to accomplish.

Eek haven’t learned anything about that stuff yet. I’m trying to use only js/html/php/css nothing more as of now.

Oh no worries, that’s the same stuff I’m learning. All the event handler stuff is javascript. It’s just a different way to call a function when an event occurs. How do you post script and tags like you did on this site? I can post some code examples of each method once I figure that out haha.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.