Function argument with jQuery selector - jquery-selectors

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.

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

function hider(className) {$("*[class^="+className+"]").hide();}
Call like so
hider("o");

Related

undefine is not a function jquery auto complete

When trying to handle the data returned from autocomplete result set this always happens.
Any clue on this issue?
$("#search").autocomplete(suggest_url,{
max:100,
delay:10,
selectFirst: false
}).result(function(event, data, formatted)
{
do_search(true);
});
Thanks
Such error happens only if you are trying to call a function, but it is not a function.
x = 123;
x(); // produces «number is not a function
y = undefined;
y(); // produces exactly «TypeError: undefined is not a function»
«Uncaught type error» indicates that exception caused inside the lambla-style function. Thus, I hope, it is something wrong with do_searh identifier. Try to alert(do_searh) before calling it.
>>> UPDATE
This questions refers to another:
jQuery UI Autocomplete .result is not a function woes

use pdo connection inside php function

I have a database class for pdo access to my db.
Inside the class I have a function :
public function isSenderIdinDB($id)
I do in my script:
$conn=new Database($credentials);
$id=something;
echo $conn->isSenderIdinDB($id);
works fine.
Now I'd like to use a function in my script, like this:
echo fn_isSenderIdinDB($id);
with:
function fn_isSenderIdinDB($id) {
return $conn->isSenderIdinDB($id);
}
But it doesn't work. I tried with a:
global $conn;
inside the fn_isSenderIdinDB function, as suggested elsewhere on SO, without success.
Any help appreciated, thanks
Nicolas
This sounds like a variable scope issue, you could try passing $conn as a parameter to your function like this.
function fn_isSenderIdinDB(&$connObj, $id) {
return $connObj->isSenderIdinDB($id);
}
And then call your function like that :
echo fn_isSenderIdinDB($conn, $id);
Perhaps it would help if we could see the whole script or the errors your are getting.

How to define a default argument value for a method in as2?

look at this code :
function a2j(trusted:Boolean=true):String
{
...
}
compiler will not accept this code in flash actionscript 2.
It looks like AS2 doesn't force you to supply the all the arguments that a function declares. At the bottom of this help page, they state that arguments you do not supply are undefined ... and that any extra arguments you supply are ignored.
Also, the answer to this question shows that you can use the arguments keyword (an Array) to work with the parameters that are passed into the function.
So for a default value, as in your example above, you could do something like this:
function methodThatHasADefault(value:Boolean):void
{
if (arguments.length == 0)
value = true;
// do something
}

Correct way to return function value instead of binding in Coffeescript

I can't seem to find a concise answer to this question. What is the correct coffeescriptic way to return the value from _otherInstanceMethod when calling #_instanceMethod instead of the function binding itself?
x = _instanceMethod: () ->
#_otherInstanceMethod key: 'value'
Edit (thanks commenters)
This returns:
x = function () {
[...] # function body omitted
});
Instead of
x = 'some value returned by _otherInstanceMethod'
I would like the value to be returned instead of the function binding to _otherInstanceMethod
Being totally new to Coffeescript, this was my fault. I was calling the instance method like:
#_instanceMethod
instead of
#_instanceMethod()
Sorry for the trouble, voting to delete
In CoffeeScript #something translated into this.something regardless of the underlying variable type. This means you can use # only in conjuction with properties, with methods you still ought to use good old this.

Coffeescript translation

If I have this javascript:
function I_did_something(){
this.test.assertExists('#selector', 'exists');
}
casper.then(I_did_something);
The problem is that casper is using call to call the then method meaning that I cannot do something like this:
#I_did_something = ->
#assertExists('#selector', 'exists')
casper.then #I_did_something
Because this does not refer to the global object.
Can anyone suggest how I would translate this into coffeescript without using the window object preferably?
You can use a fat arrow (=>) to bind the function to the current this:
#I_did_something = =>
#assertExists('#selector', 'exists')
That has a similar effect to:
that = #
#I_did_something = ->
that.assertExists('#selector', 'exists')
and I think that's what you're after.