![]() |
Class names and reducing onclick events...
One day I'll finally find the time to sit down and learn AJAX, but until I do...
Long story short: javascript Code:
So that an element with the class 'a_parent' opens 'a_child', and 'b_parent' opens 'b_child' etc. |
sketch? Where are youuuuu? SKETCH?! ;)
|
I know this isn't jQuery, but this should give you a good idea how to do it.
javascript Code:
|
Forgive my ignorance, but since that's a function, wouldn't I still have to implement it in an onclick event? The reason I ask is because the current function I use looks like this;
javascript Code:
...and works via the following (shown in its php form); php Code:
The solution I'm hoping for would allow me to remove the onclick attribute completely, reducing the amount of html generated. This is part of a WordPress plugin that generates long lists of MLS listing results, so every byte I reduce in the generation, the quicker things will load. |
This won't allow you to remove them, but it will allow you to only assign the onclick event handlers to specific elements. Just pass it an array of element ID's that you want it to watch and it should work.
javascript Code:
|
Quote:
without properly understanding your problem, its 00:30 atm so my brain isnt working fully! Bit of jQuery magic: javascript Code:
html Code:
And a small bit of css: css Code:
Is that what your after my dear friend? or have I completly mis-understood?! (which incidentally, wouldnt surprise me, me brains a bit low on the energy front) |
Sigh, just thought this might also be what you may need (even simpler if it is!):
javascript Code:
html Code:
and with that, Im off to bed! |
After looking it over, I'm thinking the second example would be a much more simplified method of doing it, which (not understanding javascript very well) hadn't even crossed my mind. All the child divs are wrapped in a parent so that should work.
I'm in the middle of completing another part of the project, but as soon as I have the chance I will try implementing this and report back on the results. I really have to take a few weeks off and learn some of this stuff. |
Quote:
|
And as a result you'll probably wind up being better at it than most of the new schoolers learning just the most recent techniques. Personally I'll probably wind up on the other side of the fence from you - jQuery has impressed me with it's ability to do pretty much everything I've ever asked from it, and I prefer to focus on PHP, not fancy schmancy effects. Just need to learn enough to be dangerous... :D
|
Quote:
|
Glad they helped and my half asleep antics were at least somewhat useful!
Yea JS isn't fabulously difficult to learn, it can however provide a massive headache when browser incompatibility comes into the equation, Internet Exploder! ARGH!!!!!! Personally I love javascript, I think its the most misused and misunderstood languages out there today and once you get to grips with its rather unconventional object model its awesome! Anyway I suppose I'd better do some work now. Now where did I put my coffee ... |
Adding on sketch's post, if you have just over an hour of free time you should check out this Google Tech Talk on: "Javascript -- The Good Parts". It's quite good and points out several common misuses of JS.
|
Quote:
|
| All times are GMT. The time now is 01:20 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0