In this situation, for example, if $(this).text() becomes 0, it will not work since in the switch 0 is not equal to "0".
In my assignment, I cannot remove " " from case.
So basically $(this).text() has to become a string somehow. Any ideas?
Thanks!
...
$( '.xyz' ).click( function()...
var key = $(this).text();
switch( key ) {
case "0":
case "00":
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
...
https://gist.github.com/188d81480a1503d1985b
If I understand you want the numeric value?
var key = parseInt($(this).text()); //or
key = parseDouble($(this).text());
Edit 2: Thanks for the suggestion Derek. Always forget that:
+$(this).text(); //also converts to integer; parseint can be given a radix (base). + if string is already in the form of a base 10 integer
Edit: Also, your code looks wrong; $(this).text()) has an unbalanced paranthesis. text() always returns a string. Which is why I made the assumption above. Although your question seems to imply you want to search by the result of text()? In that case you would want a string though, which text() gives you.
If you could give us more details and code it'd be easier to understand
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With