JQuery selector question for classes / ids containing the same number -


My website has a set of elements with "element 1", "element2", "element3", etc. Also, another set containing element with class "1", "2", "3" is not directly related to dom, so I can not use parent / child selectors.

I want to write a junky script when the user enters "element 1", then an effect / function "1".

Of course, I do not want to write all the pairs manually. How can I write this code so that the selector can detect the numbers in the class names? Do I need to use regular expressions?

I can change my HTML if needed.

If you want to use just one bit code to affect all your elements, then Should do something:

  $ ('.overover'). Hover (function () {var element = $ (this) .attr ('class'). ('Hover', ''); element = element.replace ('element', ''); $ ('.' + Element) .slideToggle ();});   

You need to add class hover to all of your elements, which you want it to do, then this element will get the number and toggles that element.

This can be a sample HTML

    

See

and a comment

Comments