In another question I came across two different ways of doing a string replacement.
One being the jQuery way $("#element").text().replace(',', '.') and the other being the pure Javascript way of first getting the text and then calling .replace(/,/, '.').
Is there a big performance hit in using the jQuery method, or any other reason not to use it (assuming you already have jQuery on the page)?
These are both essentially the same method.
$('#element').text()returns a string, so you’re calling String.prototype.replace() in both examples.The only difference I can see is that in the first method, you are using a string for the replacement, and in the 2nd, you are using a regular expression. In the examples you gave, the string method will be faster:
http://jsperf.com/string-replace-vs-regexp
If you really want to get the best performance, I’d suggest using pure JavaScript:
document.getElementById( 'element' ).innerText.replace( ',', '.' )