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);
}
Assuming you’re passing
"#hello"as the selector, you are then trying to get theleftproperty of a string, which doesn’t exist."#hello[left]", on the other hand, searches for an element with the IDhelloand aleftattribute.They are not the same. Try
$selector+"[left]"