Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$("ele").append() strips text in a mixed string. #105

Open
envygeeks opened this issue Dec 6, 2012 · 4 comments
Open

$("ele").append() strips text in a mixed string. #105

envygeeks opened this issue Dec 6, 2012 · 4 comments

Comments

@envygeeks
Copy link

Doing: $("<p>").append("<span>Here</span> Gone") Results in only <span>Here</span> being appended.

The above seems unintuitive to me. I am wondering if this could be considered a bug or if it's really intended to happen? If it's intended I was wondering if there was a rational reason this happens because it seems that we have to literally go out of our way when building with $("") it also means that if we want to continue to use $("") to build we must pull the $().html() and join it when trying to add multiple (seperately built) pieces to the element and then on the last part of the chain just use $("").html like below:

twt_paragraph.append(twt_anchor);
twt_ele.html(twt_paragraph.html(twt_paragraph.html()+link_users(tweets[i].text)));

According to Ender and the DOM I have "0.4.3-dev".

@ded
Copy link
Owner

ded commented Dec 7, 2012

upgrade!! 👍 we are at 1.3.1 https://github.com/ded/bonzo/blob/master/package.json#L4

you could probably also use an Ender upgrade if you haven't done that in a while too.

npm install ender -g

then go into your working bonzo package...

ender refresh

best of luck

@ded ded closed this as completed Dec 7, 2012
@envygeeks
Copy link
Author

Sorry I read the version string wrong (I read it from the DOM because I deleted the node_modules folder and all that) so I rebuilt and retested (without upgrading) and I was actually using 1.3.1 so this issue is against 1.3.1 not the version I listed.

On a side note the _VERSION in $ and ender says "0.4.3-dev" for some reason.

@ded ded reopened this Dec 7, 2012
ded added a commit that referenced this issue Dec 7, 2012
@ded
Copy link
Owner

ded commented Dec 7, 2012

cc @rvagg

@rvagg
Copy link
Collaborator

rvagg commented Dec 8, 2012

I'm not sure what we should do about this. The behaviour is definitely intended, we internally do a check for nodeType == 1 in create() and only return created elements for which that is true. If we expanded it to text nodes (nodeType == 3) then we'll end up with all sorts of weird behaviour:

bonzo.create('<p>foo</p> <span>bar</span>')
 // -> [ '<p>foo</p>', ' ', '<span>bar</span>' ]

i.e. 3 elements, the middle one a text node. Currently create() will skip over that element for the return list.

Which is the same thing that would happen for the manipulation methods that return the created elements: appendTo(), prependTo(), insertBefore(), insertAfter().

I'm personally just in favour of saying that if you really want to create/append text nodes then you should be wrapping them in something else. But I know that may not be the ideal solution for others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants