0

I am editing the wordpress js and was unable to do so as I am not a jquery expert so i decided to post question here i am wondering to set the font size of AM or PM to small but in js the html is not working i know that would be possible as when i place html tags it is not converting just showing as html output

$time.text(hours + ":" + minutes +  ampm);

at the place of ampm i would like to wrap it up with

si i tried to do like this
$time.text(hours + ":" + minutes +"<p class='small'>" + ampm + "</p>");

the output is coming as

03:25 <p class='small'> PM </p>

so the html is harcoded not converting can anyone help me out with this concern ?

Usman Khan
  • 359
  • 1
  • 13
  • is time an id or class? Shouldn't it be inside brackets? – NiallMitch14 Dec 23 '15 at 12:44
  • 2
    Use `.html` instead of `.text` – John C Dec 23 '15 at 12:44
  • @JohnC You could have posted it as an answer itself ;-) – Abhi Dec 23 '15 at 12:45
  • Not a direct dupe but it'll explain what the problem is and how it can be solved. There'll be other hundreds of direct dupes but this is better as it explains both `text` and `html`. – Tushar Dec 23 '15 at 12:46
  • 1
    @Abhi yeah I know, it just felt a bit short for an answer – John C Dec 23 '15 at 12:47
  • okay so .html will do the same as .text do but difference will be it wil convert show the html right ? – Usman Khan Dec 23 '15 at 12:56
  • @UsmanKhan `html()` will render the HTML whereas `text()` will encode the HTML to entities and will show the text on page. See the link above question to know the difference between `html()` and `text()`. – Tushar Dec 23 '15 at 13:09

2 Answers2

5

change .text to .html:-

$time.html(hours + ":" + minutes +"<p class='small'>" + ampm + "</p>");

jQuery Docmentation

.text = Set the content of each element in the set of matched elements to the specified text.

.html = Set the HTML contents of each element in the set of matched elements.

Community
  • 1
  • 1
BenG
  • 14,826
  • 5
  • 45
  • 60
4

.html() treats/interpret the string as HTML whereas .text() treats the content as text

Thus you need to use.html() instead of .text():

$time.html(hours + ":" + minutes +"<p class='small'>" + ampm + "</p>");
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125