This project is archived and is in readonly mode.

#1241 ✓invalid
joe

el.set(text) kill all html elements in el

Reported by joe | June 9th, 2011 @ 02:15 PM

el.set('text','text notes');
using this has the same effect like el.set('html','notes');
all children elements like div, input.. will be substitued (killed) by the text notes.

Comments and changes to this ticket

  • Arian

    Arian June 11th, 2011 @ 03:30 PM

    • State changed from “new” to “invalid”

    This is indeed how it should work (and works)

  • joe

    joe June 12th, 2011 @ 09:19 AM

    Arian, i can't believe that this is what the function shout do.
    How can I set only the text of an element then?
    And what's the different between set('html') and set('text')?

  • Arian

    Arian June 12th, 2011 @ 10:33 AM

    First HTML:

    <div id="bar">old <em>content</em></div>
    

    set text:

    $('bar').set('text', 'new <em>text</em>');
    

    resulting html. So all the content of the element is replaced by the new text. And the html is text too, so new <em>text</em> is actually displayed in the browser.

    <div id="bar">new &lt;em&gt;text&lt;/em&gt;</div>
    

    set html:

    $('bar').set('html', 'new <em>html</em>');
    

    new HTML. All the content is replaced by the HTML.

    <div id="bar">new <em>text</em></div>
    

    That's how it works, nothing more, nothing less ;)

  • joe

    joe June 13th, 2011 @ 12:42 PM

    Hello Arian,

    to first HTML:

    <div id="bar">old text
         <div id="divbar">another div with content</div>
    </div>
    

    with $('bar').set('text', 'new text');

    i expect this result:

    <div id="bar">new text
         <div id="divbar">another div with content</div>
    </div>
    

    with $('bar').set('hrml', 'new text');

    i expect this result:

    <div id="bar">new text</div>
    

    but in both cases I get this:

    <div id="bar">new text</div>
    
  • Arian

    Arian June 13th, 2011 @ 12:57 PM

    You could try something with http://mootools.net/docs/core/Element/Element#Element:appendText for that.

    What you expect doesn't make much sense though, why would it set the text before the child elements, not after or between. This is also how the native methods works or how other libraries work.

  • joe

    joe June 13th, 2011 @ 03:17 PM

    Hi, Arian,
    with appendText I only <> a text. What I would like to do is to <> a text.
    It makes sence when you wont to change as example a user message after a submit in a given div-area
    Of curse there are other posibilities to do that, but there are allways given.

    I think in the past it worked like i decribe above.
    

    On the other hand why I should use set('text'). I can do also something like this
    var text = exHtmlText.toStr();
    el.set('html',text)
    thats a very easy way, so you can use the function as i describe above, because to change the text is much more complicated.

    but this decission is not up to me...
    thanks for support

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Pages