I am currently dealing with a complex issue on how to bind a JavaScript event to an innerHTML DOM element. The scenario involves having a div with an input checkbox inside it, along with some pre-existing JavaScript event bound to that checkbox. Additionally, there is another div containing some text content. Now, through JavaScript, the goal is to create a new div where the content will be a combination of the existing two divs, while maintaining the JavaScript event for the checkbox.
While I have managed to achieve most of this task successfully, there's one challenge remaining. When transferring the checkbox from the previous div to the newly created div using innerHTML, the JavaScript event does not carry over.
The current HTML structure looks like this:
<div id="text_holder">
"Lubricant"
<input type="checkbox" id="Lubricantc" class="check_class">
</div>
<div id="text_holder2">
SKF,FAG
</div>
"text_holder" and "text_holder2" are the names of the two existing div elements.
The JavaScript code responsible for creating a new div, combining data from the previous divs, and placing it in the new div is as follows:
var previous_ig_content=document.getElementById("text_holder");
var previous_brand_content=document.getElementById("text_holder2");
var child_div=document.createElement('div');
child_div.id=ig_id+"div";
child_div.innerHTML=previous_ig_content.innerHTML+previous_brand_content.innerHTML;
I have conducted extensive research to solve this issue but haven't found a proper solution yet. Any assistance in resolving this matter would be greatly appreciated. Thank you in advance!
Below is my complete JavaScript code:
<!-- Your JavaScript code goes here -->