How to remove duplicate option from Select dropdown using JQuery

+30 How to remove duplicate option from Select dropdown using JQuery <!DOCTYPE html> <html lang=”en”> <head> <title>Codelizar – Remove duplicate options</title> <link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css”> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js”></script> <script src=”https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js”></script> </head> <body> <h1>Method 1</h1> <select id=”sel_box”> <option value=””>All Equipment</option> <option value=”1″>Dumbells</option> <option value=”2″>Plates</option> <option value=”3″>Rodes</option> <option value=”4″>Benches</option> </select> <h1>Method 2</h1> <select id=”sel_box_another”> <option value=””>All Equipment</option> <option value=”1″>Dumbells</option> …

Add or set value in data-attribute using JQuery

+20 Add or set value in data-attribute JQuery <html> <head> <title>Codelizar JQuery Data Attribute</title> <script src=’https://code.jquery.com/jquery-3.4.1.js’></script> </head> <body> <div id=”mybox” data-boxval=”98″></div> <div id=”newbox” data-mygroup=””></div> </body> <script type=’text/javascript’> var new_value = $(‘#mybox’).data(‘boxval’); //get the value from div $(‘#newbox’).data(‘mygroup’,new_value); //set the value </script> </html>

How to remove all options from dropdown and add new option in JQuery

+10 How to remove all options from dropdown and add new option in JQuery <html> <head> <title>Codelizar JQuery Blog</title> <link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css”> <script src=”https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js”></script> <script src=’https://code.jquery.com/jquery-3.4.1.js’></script> <script type=’text/javascript’> $(document).ready(function(){ $(‘#select_box’) .empty() .append(‘<option selected=”selected” value=”4″>Android Studio</option>’) ; }); </script> </head> <body> <select id=”select_box” class=”form-control”> <option value=”0″>Select Software</option> <option value=”1″>Eclipse</option> <option value=”2″>VLC Media Player</option> <option value=”3″>WinZip</option> </select> …