I am new to jQuery and I need some assistance with very simple code. So, I have a string variable that I want to print in the p with listprice class.
<script>
$(document).ready( function() {
var string = "US $257.31";
$('.listprice).append(string);
}
</script>
Any ideas how can I achieve that?
Thank you,
H
You could do this
var string = "US $257.31";
$('.listprice').html(string);
http://jsfiddle.net/jasongennaro/akpn3/
Of course, this assumes there is nothing in the p
as it would replace everything in there.
To add it on a separate line when the p
contains content, do this
$('.listprice').append('<br />' + string);
http://jsfiddle.net/jasongennaro/akpn3/1/
EDIT
As per your comment
Do you know how can I do that with regular javascript? I think they are blocking jquery in there.
You could do this
var string = "US $257.31";
var a = document.getElementsByTagName('p');
a[0].innerHTML += string;
http://jsfiddle.net/jasongennaro/akpn3/2/
This finds the first p
and adds the variable string
.
You're missing a '
.
$('.listprice).append(string);
should be
$('.listprice').append(string);
EDIT: Also missing a )
at the end.
Other than that it's fine.
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