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.
You've it right except for some typos (and I added tag specifier to make the lookup bit faster):
$(document).ready( function() {
var string = "US $257.31";
$('p.listprice').append(string);
}
The above code will append US $275.31
to all elements with the listprice
tag.
If you want to append it only to p
tags with listprice
, specify $('p.listprice').append(...
.
Oh, and remember to close your quotes after the identifier (listprice
).
You aren't appending (adding an element to another). You just want to change the p
text.
$(".listprice").text(string);
You Can Also Print Your Variable Value Between String Look like...
var filename = $('#resume').val();
$("#msg_show").text("Your resume "+filename+" has uploaded successfully. If you wish to upload a different document, please click the “Submit your Resume” button and select your file again.");
精彩评论