Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!
can someone help me translate this from Jquery to Javascript? i suppose the code itself is the same but the selectors are different right?
$(document).ready(function () {
var interest = 4.5;
var price = parseInt($('.car-price').data('carprice'));
var defaultPricePerMonth = price / 36 * interest;
$('span.result').text(defaultPricePerMonth + ' kr');
$('#months').on('change', function () {
var selectedPeriod = parseInt($(this).find('option:selected').val());
var calculatedPrice = price / selectedPeriod * interest;
$('span.result').text(calculatedPrice + ' kr');
});
console.log()
});


What I have tried:

Ihave tried to find some sites to help me but i dont really know how to do the changes
Posted
Updated 24-Oct-19 9:45am
Comments
ZurdoDev 24-Oct-19 14:56pm    
jQuery is written in Javascript so is there any reason you want to do this?
ZurdoDev 24-Oct-19 15:04pm    
jQuery is written in Javascript so is there a reason you want to do this?

 
Share this answer
 
$(document)


Basically, when the page has rendered...

$('.car-price')


Get the element with the class tag "car-price"...

.data('carprice')


Extract the arbitrary key-value pair given the key "carprice". Read me here[^].

parseInt(


convert it to an integer.

$('span.result')


Find the span elements with the class "result" (I think!)

$('#months')


Find the element with the id of "months"

$(this).find('option:selected').val()


This is getting the value of radio button that is selected. jQuery selectors[^].

Everything else is just repeat of these patterns.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900