Skip to content

Text related

Arthur Guiot edited this page Sep 27, 2017 · 2 revisions

$.text()

This function will simply put the text you have written into an element (obviously what did you expect 😂). This function will run the $.xss() function before putting the text.

Example

JS:

$.text($.select(".myCoolElement"), "Hello World 🌎!")
// Hello World 🌎!

$.html()

I won't detail much about this function because it's exactly the same as $.text(), but without running the $.xss() function. I don't think 🤔 you need an example for this.

$.append()

This function will basically take the content of an element and add some HTML.

Example

Let's say you want to do a fancy countdown, like Countdown: 1...2...3... Boum!.

HTML:

<h1>Countdown: </h1>

JS:

var i = 0
window.setInterval(function() {
    i++;
    if(i > 0 && i < 3) {
        $.append($.select("h1"), i + "...")
    }
    else if (i == 4) {
        $.append($.select("h1"), "Boum!")
    }
    else {
        // Do nothing
    }
}, 1000)

$.after() & $.before()

These function will basically insert adjacent HTML after and before the selected element.

Example

HTML:

<div class="testEl">I'll have before and after HTML when DisplayJS will do its work</div>

JS:

$.before($.select(".testEl"), "<h1>Hello, I'm the before HTML</h1>")
$.after($.select(".testEl"), "<h1>Hello, I'm the after HTML</h1>")

$.empty()

This function will empty the content of an element (not inputs, for that, see the $.emptyVal() function). You simply have to give it the element and it will empty it.

Example

HTML:

<h1>I'm sad 😭, I'll be empty soon</h1>

JS:

$.empty($.select("h1"))

⚠️ Questions?

Don't hesitate to ask your questions ⁉️ in the issue part 😁

Clone this wiki locally