I am attempting to loop through some variables and replace any instance of a space or an &
with an underscore. I have it working for spaces, how would I go about adding the &
as well?
$(function() {
$('div').each(function() {
var str = $(this).text(),
str = str.replace(/\s+/g, '_').toLowerCase();
console.log(str);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>Testing</div>
<div>Testing This</div>
<div>Testing & This</div>