Search
 
SCRIPT & CODE EXAMPLE
 

HTML

can get input value from dangerouslysetinnerhtml

// main.js

const { useEffect, useState } = React;

const htmlData = {
  htmltag: `<div><p><input type="text" placeholder="Enter text here" /></p></div>`
};

const App = () => {
  const [data, setData] = useState('');
  
  const onKeyUp = event => {
    setData(event.target.value);
  }

  useEffect(() => {
    const divId = document.querySelector('#my-inputs');
    const input = divId.querySelectorAll('input');
    if (input && input.length > 0) {
      input[0].addEventListener('keyup', onKeyUp);
    }
  }, []);
  return <div><h3>HTML Generated:</h3><div
        id="my-inputs"
        dangerouslySetInnerHTML={{ __html: htmlData.htmltag }}
      /><hr /><h3>Result:</h3><code>{JSON.stringify(data)}</code></div>
}

ReactDOM.render(<App />, document.getElementById('root'));
Comment

PREVIOUS NEXT
Code Example
Html :: action button dropdown 
Html :: html void 
Html :: empty link javascript 
Html :: randome code 
Html :: vue router link dynamic id 
Html :: how to make an element unclickable 
Html :: econnreset 127.0.0.1 
Html :: how to use pyscript in html 
Html :: Can I customize the Work Order Tablet View? I want all the buttons at the top. odoo 
Html :: copyright symbol html 
Html :: html open things in new tab 
Html :: copyright in html 
Html :: bootstrap text warning color 
Html :: pass a method to composite jsf 
Html :: tfoot renders after thead and before tbody 
Html :: mpdf table font size problem 
Html :: html5 video player 
Html :: square div 
Html :: change the text of input file in html 
Html :: menu icon html code 
Html :: koa get url params 
Html :: happy birthday html animation 
Html :: click on div with class javascript 
Html :: input type text cache clear 
Html :: html phone click to call 
Html :: onclick hide div javascript 
Html :: vue render html raw 
Html :: button email html 
Html :: how to show little description on hover html 
Html :: ex:html 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =