Plugins

The plugins site is currently in development.

We've been looking to provide a higher-quality, spam-free experience at the plugins site for some time, and a major error on our part forced us to shut down the current site before we could put the new one in place. We are developing a new site, and you can follow along with its development on GitHub. For more information about this transition, including steps you can take as a plugin author to prepare, please read our post about what's going on.

Port of PrototypeJS identify() function


This is a quick plugin that behaves like Prototype's Element.identify function, which returns an element's id attribute if it exists, or sets and returns a unique, auto-generated id. In other words, if you have an HTML block that looks like this:

<span id='test_2'></span>
<span>test1</span>
<span>test2</span>
<span>test3</span>

And call the plugin like this:

$('span').identify('test');

It will generate this:

<span id="test_2"></span>
<span id="test_1">test1</span>
<span id="test_3">test2</span>
<span id="test_4">test3</span>

You can also pass an optional second argument for what the separator string should be between the prefix specified and the unique number used. So HTML like this:

<div class='test'>Hi There</div>
<div class='test'>Aloha</div>

Called by this:

$('div.test').identify('testers','-');

Will make the HTML be:

<div id="testers-1" class="test">Hi There</div>
<div id="testers-2" class="test">Aloha</div>

Much like every other jQuery function, this is an iterable function.

If no prefix is specified, the plugin will default to "anon_element" and "_" for the separator.

Downloads



5
Your rating: None Average: 5 (1 vote)