javascript - How to remove the elements -
i need (under code can see need)
here code:
html
<input type="number" id="elementnr"> <button onclick="thefunction()">remove it</button> <p id="theelements"/>
javascript
<script> var cars = ["bentley", "ferrari", "bmw", "mercedes", "lamborghini"]; document.getelementbyid("theelements").innerhtml = cars; function thefunction() { delete cars[3]; document.getelementbyid("theelements").innerhtml = cars; } </script>
right code when click button removes 3rd element(mercedes) because gave function wanted know if there's way edit code when type number 4 in textbox , click button removes 4th element or if type 2 on textbox , click button removes 2nd element etc.
very strange question... of course possible though. know how getelementbyid. can same input element , read value property, question remains. why want it...
Comments
Post a Comment