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

Error using .html() to copy html from one element to another #12

Closed
ghost opened this issue Sep 26, 2014 · 5 comments
Closed

Error using .html() to copy html from one element to another #12

ghost opened this issue Sep 26, 2014 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 26, 2014

$("#destination").html($("#source").html()) for copying content from one element to another fails in _.html/_.init

http://codepen.io/anon/pen/DhFHC

It appears that the main _.init function that deals with selector does not handle leading/trailing whitespace. If the innterHMTL has leading whitespace, _.init fails to recognize it as an HTML string.

One thought to address it would be to trim the selector in _.init in the section that checks if it's an HTML string. I can make a pull request if you think that is a reasonable route.

@ghost ghost changed the title $("#destination").html($("#source").html()) error Error using .html() to copy html from one element to another Sep 26, 2014
@kenwheeler
Copy link
Collaborator

Great catch. I'm going to check the perf against modifying the Regex vs trim.

@ghost
Copy link
Author

ghost commented Sep 26, 2014

Cool, I can submit a pull request with trim if you want me to. Or if you want to take it, that's cool too.

ghost pushed a commit to pellucidanalytics/cash that referenced this issue Sep 26, 2014
- Fix fabiospampinato#12 - Error using .html() to copy html from one element to another
@kenwheeler
Copy link
Collaborator

@andypellucid I don't think I'm going to go with trim. $('

') shouldn't create a div. I think in the HTML method I'm going to check for an object first, and then if it's not, append whatever is there to the callee. So that something like $(callee).html('.this

- is the className for this

') will actually work.

@ghost
Copy link
Author

ghost commented Sep 26, 2014

Ok, sounds good, I'll just close my PR

@kenwheeler
Copy link
Collaborator

Fixed

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

Successfully merging a pull request may close this issue.

1 participant