placeholder in div in p5js

how to add placeholder in div created by createDiv() in p5js?

Tagged:

Answers

  • You can check the dom function id(). I suspect you could do something like this (I can't tested at the moment)

    var dd=createDiv('Parent DIV');
    dd.id('mydiv');
    

    Then in your code, you can grab your div:

    var adiv=select(''#mydiv');

    Then you have two options:

    var xtra=createDiv('Another division');
    xtra.parent(adiv);
    //OR
    xtra.parent(dd);  //In the case dd and xtra are on the same variable scope
    

    More in the p5js.org >> libraries >> dom : select(), parent(), id()

    Kf

  • thanks for suggestion.This makes div inside a div,how to use this concept to adding placeholder text inside the div.

  • placeholder text

    Sample code please? You mean like a paragraph, an HTML component?

    Kf

  • edited May 2017
    var placeholder="start typing";
    var div=createDiv(placeholder);
    div.attribute('contenteditable', 'true');
    

    when we click on div, placeholder text disappears and my typing is shown in the div.

  • Have you consider input()? Not sure if you can make it multiline.

    There is a way to do it using canvas +text() under p5.js but my impression is that you want to stick to HTML elements?

    Kf

Sign In or Register to comment.