How to transfer content from a 'contenteditable' div to a textarea or input?

2

I'm having a problem trying to transfer content from% ed to DIV with Jquery.

The code I'm using is this one:

function setData(id) {
    id.className = "input editavel esse";
    var valor = $(".esse").text()
    $(".esse").next("td").children("textarea").text("\""+valor + "\"")
    $(".esse").removeClass("esse")
}

This function is called in textarea of onchange works perfectly when I change content of div when typing, but when content comes dynamically from the database (HTML table) the function replaces div with content instead of putting the same inside it.

    
asked by anonymous 23.06.2015 / 15:42

1 answer

1

The .text("\""+valor + "\"") is usually used to manipulate the DOM and not the value of the field (I do not know the core of jQuery deeply), I also do not understand the quotes here "\""+valor + "\"" .

To summarize, if you are picking up the text using $(".esse").text() , you will not get richtext, you will only get pure text.

Use .val , so try using it this way:

 function setData(id) {
        id.className = "input editavel esse";
        var valor = $(".esse").text()
        $(".esse").next("td").children("textarea").val(valor)
        $(".esse").removeClass("esse")
    }

Note that when using .esse , will get all elements with this class, I believe the correct one would be to get id (I believe this id is an html / dom element), if this setData(id) is a string or int , this is wrong:

id.className = "input editavel esse";

    
24.06.2015 / 19:18