Reputation: 682
I am working on a script and not sure why this isn't working
function moveIn($selector) {
if( $( $selector[left] ) != null ){
$direction = 'left';
}else{
$direction = 'right';
}
This is does work:
if( $( '#hello[left]' ) != null ){
This is essentially what I am trying to get spit out. It seems the brackets are causing the problem. How else would this be written? Tips for future coding? Thanks
Entire function:
function moveIn($selector) {
if( $( $selector + '[left]' ) != null ){
$direction = 'left';
}else{
$direction = 'right';
}
var animation = {};
animation[$direction] = 0;
$($selector).animate(animation, 1500);
}
Upvotes: 2
Views: 57
Reputation: 324650
Assuming you're passing "#hello"
as the selector, you are then trying to get the left
property of a string, which doesn't exist.
"#hello[left]"
, on the other hand, searches for an element with the ID hello
and a left
attribute.
They are not the same. Try $selector+"[left]"
Upvotes: 3