I want to get only the numbers(123) not the text(confirm), here is my code
<p>123confirm</p>
<script type="text/javascript">
$(document).ready(function(){
$('p').click(function(){
var sd=$(this).text();
alert(sd);
});
});
</script>
You can use
parseIntfor this, it will parse a string and remove any “junk” in it and return an integer.As James Allardice noticed, the number must be before the string. So if it’s the first thing in the text, it will work, else it won’t.
— EDIT — Use with your example: