javascript, click I want to get text from the event

Asked 2 years ago, Updated 2 years ago, 43 views

Hello, I am a first-year developer who is developing the web. We are developing using Python Flask framework and Jinja template. Below is the html source code.

...
<body>
<div id="parent_of_display_btn"></div>
<div id="display_title"></div>
...
<input type="text" id="input_title" name="input_title">
...
<Button onclick="Something();"> Recall</Button>
...
<script src="{{url_for('.static', filename='js/custom/custom.js')}}" }" type="text/javascript"></script>
</body>

Below is the code for the custom.js file.

function Something(){
    div = document.createElement('div');
    div.setAttribute("id", "display_btn");
    document.getElementById('parent_of_display_btn').appendChild(div);
    ...
    ..
    $('#display_btn').off('click');
    $('#display_btn').click(function() {
      document.getElementById('display_title').innerHTML = document.getElementById('input_title').value;
    });
}

If you press the recall button with the source, create a div with the id display_btn and add it as child to parent_of_display_btn. And when you press the created display_btn, you put the text value of input_title in the click function to display the text value in the div with the display_title ID.

However, when you run it, even if you enter input_title, document.getElementById('input_title').Value has a value of null. document.getElementById ('input_title') outside of the click event.When I approach the value, I read the value well, but I can't read it in the click event. Ask them what the cause is and how to solve it.

javascript html jquery

2022-09-22 12:41

1 Answers

https://jsfiddle.net/mps8e95z/

I checked on jsfiddle and it works as you intended.

There seems to be a possibility that another code is not written here.


2022-09-22 12:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.