How to Add Or Remove Row Dynamically in HTML Order List Using JavaScript JQuery With Row Count (index) Value | Create dynamically add/remove rows in html List using JavaScript

2,052 views


Hey guys, today in this post we are going to learn about How to Add Or Remove Row Dynamically in HTML Order List Using javascript jquery With Row Count (index) Value.

Files we used in this post example:

addRemoveRows.html HTML File It is used for create a add/remove rows for display the browser on button click.

addRemoveRows.js

JavaScript File It is holding add/remove rows JavaScript dynamically Functioality.

addRemoveRows.css

Style CSS File It is used for Image slider and Button Alignment.
jQuery Library

JQuery Library Min File It is a JQuey Library that is provided by JQuery

Download Supported jQuery Library for add/remove rows dynamically.

Final Output

dynamically add/remove rows in jquery -- w3web.net

 

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
   

You can download file directly from github by Click Here.

 

Other related post that would you like to learn in Salesforce

 

Step 1:- Create HTML File : addRemoveRows.html

addRemoveRows.html [HTML File]

  1.   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>dynamically add/remove rows in html List using javascript JQuery</title>
  6. <script type="text/javascript" src="http://w3web.net/wp-includes/js/jquery-1.7.1.min.js"></script>
  7. <script type="text/javascript" src="include/addRemoveRows.js"></script>
  8. <link rel="stylesheet" href="include/addRemoveRows.css" type="text/css" media="all">
  9.  
  10. </head>
  11. <body>
  12. <div>  
  13.    <input class="addButton" type="button" id="mybtn" value="Add" />
  14. </div>
  15. <ol id="main">
  16. 	<li id="myItem" style="display:none">	        	
  17.         <input class="inputFld" type="text" value="" />
  18.         <select class="inputFld">
  19.             <option>--Select--</option>
  20.             <option>India</option>
  21.             <option>Colombia</option>
  22.             <option>Egypt</option>
  23.             <option>Indonesia</option>
  24.             <option>Malaysia</option>
  25.         </select>
  26.         <a class="crossIcon" href="javascript:void(0)" rel="0" onclick="deleteItem(this)" title="Remove">&#10006;</a>
  27. 	</li>
  28. </ol>
  29.  
  30.  <br/>
  31.    <!--Start RelatedTopics Section-->
  32. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  33.  
  34.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
  35.  
  36.             <br/><br/>
  37.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like →</span> </strong></p>
  38.             <div style="display:block; overflow:hidden;"> 
  39.                 <div style="width: 50%; float:left; display:inline-block">
  40.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  41.                         <li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
  42.                         <li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
  43.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
  44.                         <li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
  45.                         <li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
  46.                     </ul>
  47.             </div>
  48.  
  49.             <div style="width: 50%; float:left; display:inline-block">
  50.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  51.                         <li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
  52.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
  53.                         <li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
  54.                         <li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
  55.                         <li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
  56.                     </ul>
  57.                 </div>
  58.                <div style="clear:both;"></div> 
  59.                <br/>
  60.                 <div class="youtubeIcon">
  61.                     <a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
  62.                 </div>
  63.     </div>
  64.  
  65. </div>
  66.  
  67.   <!--End RelatedTopics Section-->
  68. </body>
  69. </html>

Step 2:- Create JavaScript File : addRemoveRows.js

addRemoveRows.js [JavaScript File]

  1.    $(document).ready(function() {     
  2.  
  3.   var index = 0;
  4. 	$('#mybtn').click(function() {		
  5. 		index++;
  6. 		$("#myItem").clone().attr("id", "myItem" + index).appendTo("#main");		
  7. 		$("#myItem" + index).find("a").attr("rel", index);
  8. 		$("#myItem" + index).show();
  9. 	});	
  10.   })
  11.  
  12.  
  13.   function deleteItem(obj)
  14.   {
  15.   	$("#myItem" + obj.rel).remove();
  16.   }

Step 3:- Create Style CSS : addRemoveRows.css

addRemoveRows.css [Style CSS File]

  1.    ol li{ padding:0 0 10px 0;}
  2.  .addButton{ background-color: #2869e0; color: #ffffff; padding: 5px 20px 5px 20px; margin-left: 40px; border-radius: 5px; font-size: 12px;  display: inline-block;}
  3.  .inputFld{border:1px #ccc solid; display:inline-block; width:200px; padding:5px 10px;}
  4.  .crossIcon{display:inline-block; padding:5px; text-decoration:none; color:#ff0000;}
  5.  .crossIcon:hover{color:#0000ff;}

dynamically add/remove rows in jquery -- w3web.net

 

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
   

Further post that would you like to learn in Salesforce

 

 


 

FAQ (Frequently Asked Questions)

How do you delete a row in a table using JavaScript?

The remove() method is used to remove the table row from an HTML table using JavaScript. remove() Method: This method removes the selected elements alongwith text and child nodes. This method also removes data and events of the selected elements.

How do I insert a dynamic row in HTML?

The insertRow() method creates an empty 'tr' element and adds it to a table. The insertRow() method inserts the new row(s) at the specified index in the table. Note: A 'tr' element must contain one or more 'th' or 'td' elements. Tip: Use the deleteRow() method to remove a row.

How do you empty a table in JavaScript?

This can be done by using JavaScript. First of all set the ID or unique class to the table. Select the table element and use remove() or detach() method to delete the all table rows.

Related Topics | You May Also Like

 
Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  

Our Free Courses →

👉 Get Free Course →

📌 Salesforce Administrators

📌 Salesforce Lightning Flow Builder

📌 Salesforce Record Trigger Flow Builder

👉 Get Free Course →

📌 Aura Lightning Framework

📌 Lightning Web Component (LWC)

📌 Rest APIs Integration



Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment