Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Shea Lewis
6,702 PointsRemoving code attribute for my well
I have designed out a section where the user can copy code from my site.
http://i.imgur.com/CyuA9ZE.png
My problem though is that I dont actually want it to do anything to my site. I just want it to be the copy without effecting anything. Is there a way to remove the attributes from this?
1 Answer
Sean T. Unwin
28,690 PointsYou could use String.replace() with a regular expression to remove the data-token portion then output the modified String.
To test, paste the following into your DevTools' console:
var s = '<script="assets.signupumo.com/script.js" data-token="gzbrwdij3oij343"></script>';
var sr = s.replace(/\sdata-token="(\w+?)"/, "");
console.log(s);
console.log(sr);
Note: be aware that your example image does not have a space before "data-token" whereas my example does. If you don't have a space then remove \s from the beginning of the RegExp.