Avatar of renisenbb
 asked on

Bootstrap question

I have a span element that showed up as a button.
<span class="button" style="button.gif" href="javascript:TestSubmit('abc')" > MyButton </span>
How do i convert it to Bootstrap?
I've tried
<button class="btn btnPrimary" href="javascript:TestSubmit('abc')" >MyButton</button>
but the javascript doesn't get triggered

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Leonidas Dosas

Comments inside the code:
<!--I removed the href attr and I set an id-->
<span class="button" id="myButton" style="button.gif"  > MyButton </span>

Open in new window

//First I set a variable to span element
var spanElem=document.getElementById('myButton');
//Then I create a button element and define it to a var
var buttonElem=document.createElement('button');
//I set the innerHTML value and the bootstrap class
buttonElem.setAttribute('class', 'btn btnPrimary');
//I use the replaceWith() function to replace the spanElem
//element with the button element.Finally I set a click event
//to span that when I click on it to replace the span element

Open in new window

I used JQuery replaceWith() function that is more easy and handful .See the replaceWith() documentation
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thank you!
Julian Hansen

You are welcome.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.