# You can write better jQuery - A DRY approach

> jQuery isn't good or bad, it's just a tool like any other. You can use a DRY approach to jQuery and improve your workflow. Here's how.

- URL: https://graffino.com/til/you-can-write-better-jquery-a-dry-approach-to-multiple-configurations
- Author: Nick Ciolpan
- Channel: javascript
- Published: 2018-09-28
- Updated: 2022-05-27

##### From this 
```
$('.multiSelectOne').multiselect({
    buttonClass: 'btn btn-default',
    buttonWidth: '100%',
    ...
});
$('.multiSelectTwo').multiselect({
    buttonClass: 'btn btn-default',
    buttonWidth: '100%',
    nonSelectedText: '---',
    ...
});
```
           
##### To This
```
<select class="js-multiselect" 
    data-include-select-all-option="true" 
    data-all-selected-text="All">
    <option></option>
</select>
```
```
$('.js-multi-select).each(function () {
	let options = {};
  
	Object.entries($(this).data())
		.map(property => options[property[0]] = property[1]);
    
  $(this).multiselect(options); 

}
```

And never go back for adjustments in the script file ever again.
