What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

I see this mostly as people asking pure JavaScript questions and getting JQuery answers -- yes, I know about the meme, but I'm talking about serious answers here -- but I would guess that it happens for other languages/extensions, too. Is this okay?

It seems like most JS questions these days get at least one JQuery response, even if JQuery is never mentioned in the post or tags. In most cases, the answers do seem to be technically valid, at least based on a lack of downvotes. On the other hand, when I ask questions, they're usually about work rather than personal projects, and I don't have control over what libraries are included. Even for personal projects, I might not want to learn how to install JQuery to solve one little problem. But I don't know if I'm in the minority on either of those counts.

This question was inspired by the comment thread on this SO answer.

share|improve this question

4 Answers 4

up vote 5 down vote accepted

Yes it's okay. If the OP wants to specifically exclude common libraries, then they need to specify that in their question. You typically get several different answers to a question, and different people reading the answers later can still benefit from the jQuery answer even if the OP chooses a plain JavaScript solution.

share|improve this answer
4  
I disagree with this answer. I think our duty as a community isn't only to provide quick fixes, but also to help fellow programmers to be better. "use jQuery" answers almost never inspire understanding. I've written my opinion in depth here –  Benjamin Gruenbaum Jun 15 '13 at 8:22
    
@BenjaminGruenbaum I don't know how you read my answer and interpreted it as support for only "quick fix" answers. –  Bill the Lizard Jun 15 '13 at 12:54

For most questions, it is absolutely fine to suggest using another language. I mean, I tell people who want to parse XML with regular expressions to use XPath all the time.

Unless they give a specific reason why they can't use a certain technology. Like maybe "My boss got beaten up by XPath as a kid and won't let me use it." Not really a good excuse, but it's enough to earn a downvote on XPath answers.

Consider the details that the asker has given and decide for yourself. It's not really something there should be a hard-and-set rule for.

Knowing a better language for a task is part of what makes an answer good. The asker doesn't know he should be using jQuery or XPath. That's why he asked the question in the first place. Just use your experience to help him.

share|improve this answer

Okay, I'm going to go out on a limb here and disagree with Bill the Lizard and Jon Skeet. So: Shields to maximum. :-) But I've answered a lot more javascript questions than they have, so...

No, it's not okay.

I'll use jQuery as an example because that's where this mostly comes up.

If someone asks a question not using jQuery and without tagging the question jquery, it's not okay to provide an answer that only helps them if they use jQuery.

It is, however, perfectly acceptable to provide an answer saying (or preferably showing) how to do it without jQuery and also, if relevant, pointing out to the person asking the question that they can probably save a lot of time and trouble if they use a library to smooth out browser differnces, provide more concise ways of doing things, etc., allowing them to concentrate on the thing they're actually trying to do.


Don't do this:

Question:

How can I change the color of a div to red?

Answer:

Using jQuery:

    $("selector_for_your_div").css("color", "red");

That's completely useless to the person asking the question if they're not using / don't want to use a library, or if they're using Prototype, or YUI, or...


Do this:

Question:

How can I change the color of a div to red?

Answer:

You can set style information for an individual element by getting a reference to the DOM element and using its style property. That's an object with properties for style information, including a color property. So:

    element.style.color = "red";

You get a reference to the DOM element for the div in various different ways depending on how you can identify it. If it has an id value, it's easy:

    document.getElementById('the_id').style.color = "red";

...but if it doesn't, you might need to use getElementsByTagName and various other DOM methods (links: core methods, html-specific, latest stuff) to find the element.


Off-topic: A lot of this stuff is a lot easier if you use a library like jQuery, Prototype, YUI, Closure, or any of several others. These sorts of libraries smooth out browser differences and offer a lot of useful functionality you can leverage, so you can concentrate on what you're actually trying to do rather than browser quirks and such. For instance, with jQuery you can do it like this:

    $("selector_for_your_div").css("color", "red");

...where selector_for_your_div can be any CSS3 selector (and jQuery adds some useful things of its own). Other libraries will have similar ways of simplifying things.


That's what I do (3,041 javascript questions answered so far...). Yes it's more work. Tough. :-) Keep a few DOM links handy and it's actually fairly easy. If you can't solve the problem without using a library, either don't answer the question, or keep your answer general and conceptual, and then (again) point out how much easier your life can be if you use a library, and reference several of them.

Note: I use jQuery in nearly all new browser-based projects I do, only not using it if there's a very good reason. It's a great library. It's not without its faults, but what is? It works very well in general, it's well-supported, has good sponsors (e.g., is unlikely to become moribund and outdated), and there are thousands of plug-ins for it (90% of which are rubbish; but 10% of thousands is still a lot of useful stuff). So I'm just saying, I'm not (remotely) a jQuery-hater.

share|improve this answer
2  
+1 I'd think that if they don't mind a jQuery answer that they'd put that somewhere in the post or add the jQuery tag to their question. If I'm honest, I personally think SO is quickly becoming one of the biggest advertising hubs for jQuery. Now smack me on the head for commenting on a 3 year old question... :P –  Qantas 94 Heavy Jun 15 '13 at 8:28
2  
@Qantas94Heavy I'd argue that it's as relevant as it was 3 years ago. If anything, it's a bigger problem now than it was 3 years ago. –  Benjamin Gruenbaum Jun 15 '13 at 8:32

I think it's pretty reasonable. If you're asking a question and expecting a suggestion to use another library, but you can't for whatever reason, then indicate that in the question.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .