1

Folks, this works correctly for me to hide any element where the class name starts with "o"

function hider() {$("*[class^=o]").hide();}

Now I'd like to be able to pass that "o" string in as the function's argument, and I have trouble with the syntax. Any help is appreciated.

2 Answers 2

3

It seems that something like this will work:

function hider(startsWith) { $("*[class^="+startsWith+"]").hide(); } try it in this fiddle: http://jsfiddle.net/JECUL/

Sign up to request clarification or add additional context in comments.

2 Comments

Almost: The 1st line below works, but only with the fixed argument. The 2nd line fails quietly. $("*[class^='z']").hide(); $("*[class^="+startsWith+"]").hide(); How can I pass the argument?
It works for me in both ways, tried it in the fiddle. if that way fails try this: $("*[class^='"+startsWith+"']").hide(); But it works both ways so it should not matter.
2
function hider(className) {$("*[class^="+className+"]").hide();}

Call like so

hider("o");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.