- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add a new list element under a using jQuery?
To add a new list element under a ul element, use the jQuery append() method
Set input type text initially
Value: <input type="text" name="task" id="input">
Now on the click of a button, add a new list element using the val() and append() methods in jQuery:
$('button').click(function() { var mylist = $('#input').val(); $('#list').append('<li>'+mylist+'</li>'); return false; });
You can try to run the following code to learn how to add a new list element using jQuery:<./p>
Example
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('button').click(function() { var mylist = $('#input').val(); $('#list').append('<li>'+mylist+'</li>'); return false; }); }); </script> </head> <body> <form> Value: <input type="text" name="task" id="input"> <button>Submit</button> <br> <p>Add a value above and click Submit to add a new list.</p> <ul id="list"> </ul> </form> </body> </html>
- Related Articles
- How to add a new row in a table using jQuery?
- How to add a new value to each element of list in R?
- How to add a new element in the XML using PowerShell?
- How to add display:none in an HTML element using jQuery?
- How to add a new element to HTML DOM in JavaScript?
- How to add and remove CSS classes to an element using jQuery?
- How to scroll to a specific element using jQuery?
- How to add description list of an element using HTML?
- How to add target=”_blank” to a link using jQuery?
- How to add a title in anchor tag using jQuery?
- Swift Program to Add a New Element in the Set
- How to insert element as a first child using jQuery?
- How to insert element as a last child using jQuery?
- How do you add an element to a list in Java?
- How to add attributes to an HTML element in jQuery?

Advertisements