I need some help with some dynamic jQuery - if it says what it will be called. In fact, I have several DIVs in a number, each with the same name, except in the end, increasing the number - for example:
.... and so forth and so forth. On the main menu, I want to make each item toggle button, so there will be a button to trigger Category-1, Category-2, and so on.
Ability to add / remove categories to become part of CMS (Wordpress), so that somehow count on jQuery how many "categories-" are on the page, and then a button for each in the main menu Create
I know how to create a toggle button in jQuery, but I'm not getting any luck, which requires me to be dynamic-well (if it's a word!). My first and only attempt has been used to use inline jQuery in PHP tags so that a jquery toggle button for each category DIV is being generated - it seems that when I look at the source, but Buttons do not work properly, probably because the PHP server is side-and-jQuery client-side. (Just an estimate).
Does anyone know how I need to create jQuery code?
Thanks Zach
This is the best way with which I can come:
var divs = $ ('div [id ^ = "category-"]'); Var num = divs.length; (I = 1; i & lt; = num; i ++) {$ ('' button class = "toggle" />) .text ('Toggle div' + i) .appendTo ('# DivToAddButtonsTo '); } $ ('. Toggles'). Live ('click', function) {var it iss = $ (this). Index (); $ ('Div [id ^ = "category -"]') Eq (this). Toggle ();}); .
Obviously this is run inside the $ .ready () . Reference:
Comments
Post a Comment