Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery (anti-)pattern: building selectors with string manipulation

Too often I find myself building selectors with string manipulation (split, search, replace, concat, +, join).

Good or bad?

like image 962
flybywire Avatar asked Nov 15 '22 14:11

flybywire


1 Answers

What's wrong with that? What are the alternatives — just hardcoding them as single strings? But you may use conventions on your site for how the layout is organized. If you just define the selector components in one place, and use it to build a selector, sounds like this would be less hassle than going through all the code and doing search-replace everywhere it shows up.

I'd say it's good assuming you have the strings otherwise organized (defined in one place, used in several places).

like image 79
Jaanus Avatar answered Dec 09 '22 19:12

Jaanus