Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set paragraph text with javascript on page load

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 :)

like image 421
Pierre Pretorius Avatar asked May 04 '12 09:05

Pierre Pretorius


People also ask

How do you set up text paragraphs?

Assuming you are trying to set the text of a p element, use text() : $("#mac001OEE"). text("0%"); val() is used on elements which have a value attribute, such as input , select and textarea .

How to set a text in paragraph using jQuery?

jQuery text() MethodThe text() method sets or returns the text content of the selected elements. When this method is used to return content, it returns the text content of all matched elements (HTML markup will be removed).

How do you change paragraphs in JavaScript?

To change the text in a paragraph using JavaScript, get reference to the paragraph element, and assign new text as string value to the innerHTML property of the paragraph element.


2 Answers

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> 
like image 142
Tats_innit Avatar answered Sep 30 '22 18:09

Tats_innit


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

$(document).ready(function() {      $("p#idname").text('test test Rambo'); }); 
like image 36
Manikandan Avatar answered Sep 30 '22 18:09

Manikandan