Stupid jQuery and CSS tricks: Move a hidden element to the end of the parent

I just came up with a solution so simple, yet so stupid, that I had to share it.

The scenario is this: my client has some third-party JavaScript to inject a form into a page. I’ve been writing some of my own CSS to style the forms, including some crafty use of :nth-of-type(2n) and :nth-of-type(2n-1) to apply styles conditionally to adjacent fields in a two-up layout. (These are just sequential <div> tags, and I have to work with what I’ve got.) Specifically, I’m adding some right margin on the “left” element, and no right margin on the “right” element.

I noticed an instance where my margins were flipped for two fields, and when inspecting the code, I discovered why: the client has set up their form with a hidden field tucked in there before the “left” element. That’s throwing off the value for 2n in my CSS. I was going to contact them and ask them to update their form to put the hidden element at the end, but I realized this is a problem that is likely to recur, so I should just write in a workaround. (Yeah, yeah. But it’s the lesser of two evils.)

Fortunately, the site is already using jQuery, so a fix was super simple. I’m leaving the CSS class names here as they are in the actual site, but you may need to change them to suit your particular form.

jQuery('.form_container .form_page .form_question.hidden').each(function() {
    jQuery(this).appendTo(jQuery(this).parent());
});

Since the hidden field has the .hidden CSS class, it’s really easy to use the jQuery .appendTo() method to just take all of the hidden fields and shove them to the end of the container element. I used the parent and ancestor CSS classes in my jQuery selector just to be sure I’m isolating this action to these particular forms. Then of course I have to tell the page when to execute this functionality, which is ideally on the load event:

jQuery(window).on('load', function() { /* Code goes here */ });

It works!

Do What You Like

How “Do What You Love” Is a Recipe for Disappointment and/or Exploitation

Note: This is a rough sketch of some thoughts that have been simmering in my head for years and that were catalyzed by a conversation I had this morning on a walk with SLP. I may turn this into something more substantial and cohesive at some point in the future. But since I also may not do that, I wanted to post this early version, such as it is, so I don’t lose these ideas altogether.

The expectation that you will find a career doing The Thing you truly love tends to lead in one of three directions:

  1. Exploitation by an industrial complex that knows you will work more hours, for less pay, with more personal sacrifice, if you believe you are following your true passion.
  2. Loss of love for The Thing as you realize the compromises you need to make in order to turn a passion into a career.
  3. Cognitive dissonance as you struggle to rationalize that whatever it is you’ve ended up doing is The Thing you believe you truly love to do, when it is not.

Don’t give away The Thing that you love.

Many industries, especially academic and creative fields, are structured in a way that assumes the majority of their most talented workers do truly love the thing that they do, and they’re optimized to exploit that passion. The expectation that you will always go above and beyond, first because you want to but eventually because the structure of the job forces you to, is baked in. You will work more hours than you should, demand less pay than you deserve, and sacrifice other aspects of your life, because you are told it’s what the job requires, and you believe it. But what the job really requires is you. Your talents and your passion, and you should be compensated adequately for those, both in terms of pay and time off. But that rarely happens.

Compromise can be a killer.

There are many aspects of life where compromise is necessary and good. But compromising The Thing you love in order to turn it into a career can very easily suck that love out of The Thing. Clients may have unrealistic or illogical demands. Promoters will want you to do The Thing their way instead of the way you know works best for you.

“Do what you love” ≠ “Love what you do”

This may be the most dangerous path of all. Very few of us can land a job doing The Thing we truly love. Incremental shifts over time, impulsive decisions made long ago, or unexpected changes due to the complex challenges of life, all can lead a person into a place where they’ve invested years of time and energy into something that has little or nothing to do with their true passion in life. But that investment is hard to throw away, and it’s easy to try to convince yourself that you are doing The Thing you love, whatever it is that you’re actually doing. Admitting to yourself that you have no real interest or passion for the job you do can feel like a massive personal failure, but the real failure is denying your personal truth.

Do what you like.

Find a job that gives you satisfaction and fulfillment, but that you can walk away from at the end of the day… or walk away from entirely, if you realize it doesn’t suit you. This is a job that you are willing to invest in enough to take seriously, to do good work, to make a decent living and to contribute to society. It is not a job that you are willing to let make unreasonable demands upon your time, your energy, your family or your personal well-being.

A job you like doesn’t crush your spirit during the working hours, and it leaves you with a good amount of non-working hours to pursue your true passion, hobbies, leisure activities, family time, whatever it is you most want out of life.

Facebook and Twitter: bane of the blogger

Fail.I’ve been writing this blog for about seven years now. My engagement with it has gone through its ups and downs; there were periods in 2004 and 2005 where I’d go for a month or more without posting. But over the last three years or so I kept up a pretty reliable stream of posts, until some point early this year when I started using Facebook and Twitter a lot. (I won’t bother linking to them — if you can’t figure out how to find them, you’re probably better off anyway.)

Some people are fairly careless about how they use their blogs (if they have them), Facebook, Twitter, etc. Every online presence is a virtual confessional, therapist’s couch, and personal reality show, all in one. It’s all out there, never mind the aftermath.

I’ve tried to be a bit more careful and organized in my approach to things: I’ll get fairly personal in my blog, but it’s mainly about my geeky interests in technology and music, where personal information (other than my tastes, such as my inexplicable fixation on ’70s progressive rock) is irrelevant. And there are lines I won’t cross.

Facebook is the more personal, friend-oriented venue for me: I assume that what I am writing there is only going to be seen by people I know; people I can reasonably trust and expect to care at some small level about personal details that are irrelevant in the context of a blog. But there are still lines I won’t cross, because it’s hard to keep track of 130+ “friends” and it’s even harder to keep track of Facebook’s nebulous, ever-changing privacy policy.

Twitter is a strange one: many people use it in many different ways. I’ve taken the approach of some blogger/Twitter quasi-celebrities (John “Daring Fireball” Gruber, Merlin “43 Folders” Mann, Andy “Waxy” Baio, Adam “Lonely Sandwich” Lisagor, Jason “Kottke” Kottke) I seek to emulate (though admittedly it’s weird when you get to an age where those you seek to emulate are your peers — or are even younger than you are): Twitter as “microblog.” If you have a clever, “blog-worthy” idea, but you don’t have time to write a blog entry, or it’s pithy enough that you think you can squeeze into 140 characters, Twitter is the perfect venue. It’s a natural complement to Facebook, in some ways: the personal stuff goes to Facebook, the public stuff goes to Twitter.

The problem is, both Facebook and Twitter encourage ill-conceived, dashed-off, incomplete thoughts. Why bother taking the time to contemplate an idea, explore all facets, carefully compose your thoughts, and perfectly craft a 500-word essay no one but yourself (and probably not even you) will ever read?

Well… what are you leaving behind? What is the legacy of your online endeavors?

Instead of a body of intelligent writing that may someday lead to something more useful, or at the very worst, will be something I can point at with a modicum of pride and say, “I did that!” all you’re left with is an unnavigable, treacherous sea of mental jetsam, and the vague sense that, at best, you’ve wasted your time and, at worst, you’ve left the back door wide open for future identity theft, libel suits, employment rejections, or something else that is presently inconceivable but will soon ruin your life because someone figured out a new way to exploit all of the unflattering information you revealed in drunken Facebook postings in 2007.

Wait, was Facebook even around in 2007? The online world is moving so fast, it’s hard to remember days before Facebook and Twitter. You know, the days when, if I wanted some online adulation, I had to take the time to compose my thoughts and write a blog entry (or, at least, write a blog entry, and maybe compose some thoughts along the way), instead of just idly loading Facebook on my iPhone while lazing on the couch and announcing to the world (or at least my so-called “friends”): “OMG! Did U C that stoopid reality show? Those morons on there are total morons… 4 realz!!!1one!”

Maybe it’s time to get less social with my networking, and get back to the one true, perfect venue for narcissistic online exhibitionism: the blog.

Or, as Lewis Black so eloquently put it…


For your reference:

John Gruber: blogTwitter
Merlin Mann: blogTwitter
Andy Baio: blogTwitter
Adam Lisagor: blogTwitter
Jason Kottke: blogTwitter


And finally, to be fair, it’s not entirely Facebook and Twitter that have led to my unfortunate neglect of this blog. Over the past six months I’ve also started two other blogs that have demanded most of my blogging energies: Hall of Prog and 52 Coffees.