mercredi 25 février 2015

How to execute click() in jQuery

This code basically takes 'textmoney' and figures out how much a person makes a year. to execute this function you have to press enter. I also have a div called 'moneydiv' that will do the same function, but it seems if i have both functions in the same script neither will work. How would i code to have the user to be able to do both functions? How would i code the click() with the div?


Jquery:



<script src="http://ift.tt/1yCEpkO"></script>
<script>
$(document).ready(function() {

var $demo = $('#demo');
var $textMoney = $('#textmoney');
var $moneydiv = $('#moneydiv');

.keydown(function(e) {
if (e.keyCode === 13) {
var money = $(this).val();
if (isNaN(money) || money === '') {
$demo.text('You aint enter no $$$$$$');
} else {
var dailyE = $(this).val() / 365;
$demo.text('$' + dailyE + ' per day');
}
} else if ($(this).val() === '') {
$demo.text('');
}
}).mouseover(function() {
$(this).css('border', '1px solid black');
}).mouseout(function() {
$(this).css('border', '1px solid grey');
});

});
</script>




Aucun commentaire:

Enregistrer un commentaire