Skip to content

Instantly share code, notes, and snippets.

@umidjons
Created July 11, 2013 11:12
Show Gist options
  • Save umidjons/5974576 to your computer and use it in GitHub Desktop.
Save umidjons/5974576 to your computer and use it in GitHub Desktop.
* Change state programmatically with trigger() // hover, focus, active, visited * Build reqular expression on the fly
jQuery(document).ready(function () {
var myElem = $('a.myClass'),
txt="hello",
longText="some very very long text with /hello/world/, wow",
pattern = '\/' + txt + '\/',// build regexp pettern on the fly, pattern=/\/hello\//
rx = new RegExp(pattern, 'i'); // create regexp object
if (rx.test(longText)) { // test - is there /hello/ in longText?
myElem.trigger('hover'); // if there is, change state of the <a class"myClass"> to <a class"myClass:hover">
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment