Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user


« Newer Snippets
Older Snippets »
5 total  XML / RSS feed 

Faster find in project

Find element position relative to other elements

Insert in place without document.write


// So, given a syndication script with a fixed ID:
<script type="text/javascript" id="syndication" src="syndication.js">script> 

// We can go from oldskool nastiness like this:

Here is some syndicated content.

'); // To modern loveliness like this: var newcontent = document.createElement('p'); = 'syndicated-content'; newcontent.appendChild(document.createTextNode('Here is some syndicated content.')); var scr = document.getElementById('syndication'); scr.parentNode.insertBefore(newcontent, scr); // We could even go a step further and remove the <script> ID, but in that case we would need a concrete method for identifying the specific element. We could do that by knowing its SRC: var scripts = document.getElementsByTagName('script'); for(var i=0; i<scripts.length; i++) { if(scripts[i].src == '') { //scripts[i] is the one break; } }

Set up Mercurial with SSH on Textdrive


if (navigator.userAgent.indexOf('Safari') != -1) {
        window.addEventListener('load', function() {
                var lock = false;
                var labels = document.getElementsByTagName('label');
                for (var i = 0; i < labels.length; i++)
                        labels[i].addEventListener('click', function() {
                                var input = (this.htmlFor ? document.getElementById(this.htmlFor) : this.getElementsByTagName('input')[0]);
                                if (input && !lock) {
                                        lock = true;
                                        lock = false;
« Newer Snippets
Older Snippets »
5 total  XML / RSS feed