Set paragraph text with javascript on page load

51,898

Solution 1

Please try .text() good read here: http://api.jquery.com/text/

demo http://jsfiddle.net/FyVzF/13/ or for your specific example using id please see here http://jsfiddle.net/FyVzF/14/

hope this helps!

code

$(document).ready(function() {

    $("p").text('test test Rambo');
});

HTML

<p> </p>

Solution 2

Try this only for a particular paragraph with the id "idname":

$(document).ready(function() {

    $("p#idname").text('test test Rambo');
});

Solution 3

$(document).ready(function () {
    $("#mac001OEE").html("0%");

});

OR

$(document).ready(function () {
    $("#mac001OEE").text("0%");

});

Solution 4

Instead of .val() use .text() or .html():

$(document).ready(function() {
    $("p").text('saeed');
});

or

$(document).ready(function() {
    $("p").html('saeed');
});
Share:
51,898
Pierre Pretorius
Author by

Pierre Pretorius

Studied BSc Computer Science at NMMU, majored in Advanced Programming and Applied Mathematics. I've been working full-time since November 2011 after graduating.

Updated on January 11, 2020

Comments

  • Pierre Pretorius
    Pierre Pretorius over 4 years

    Basically all I want to do is set the text of a paragraph using JavaScript/jQuery on page load. This is for a simple Kendo UI app.

    Can anyone please give me a method of doing this?

    I know this is probably a noob question, but I'm semi inexperienced with JavaScript/jQuery.

    This is what I've already tried, but it doesn't seem to be working...

    <script type="">
            $(document).ready(function () {
                $("#mac001OEE").val("0%");
            });
    

    This code has been placed in the head of the HTML page.

    Thanks :)