:) First of all, sorry my bady english :p I was taking a look to the next js code fragment:
var classes = element.className.split(/\s+/);
That code will split the full classname of and element into an array containing every class... but, what's the difference between using .split(/\s+/)
, and using .split(" ")
? i see the same result...
I tested this with the next simple code in Chrome:
<!DOCTYPE html>
<html>
<body>
<div id="cono" class="clase1 clase2 clase3-xD">
</div>
<script>
var d = document.getElementById("cono");
console.log(d.className);
var classes = d.className.split(" ");
for (i in classes) {
console.log(classes[i]);
}
</script>
</body>
</html>
I have the same result whether i use .split(" ")
or .split(/\s+/)
:
clase1 clase2 clase3-xD
clase1
clase2
clase3-xD
Do they have any relevant difference?
\s
captures more whitespace than just the space character