0

I am going to call the elements of the following array into jquery.

$options[] = array( 'title' => 'Upload Favicon',
 'id' => 'favicon',
 'type' => 'upload' );

I have tried the following, but it does not work..

jquery("'.$option['id'].'").hide();

May be I am wrong, but I myself guess that it is because in the jquery code there is no # for id calling, but I do not know how to add #.

Please help..

Lion
19.1k22 gold badges83 silver badges111 bronze badges
asked Jul 1, 2012 at 17:22
1
  • jQuery("#'.$option['id'].'").hide(); I guess? Commented Jul 1, 2012 at 17:27

1 Answer 1

1

The obvious problem is here:

$options[] = array( 'title' => 'Upload Favicon', 
 ^^

This says "add an element to the array $options, and set that element's value to the array 'title' => 'Upload Favicon'.... If $option is not yet set, it will be created as an array. So it will effectively be like this:

$options = array (
 array ('title' => 'Upload Favicon',
 'id' => 'favicon',
 'type' => 'upload'
 );
);

This probably isn't what you mean, simnce you'll need to access it like this:

$options[0]['id']

To fix it, remove the []:

$options = array( 'title' => 'Upload Favicon',
 'id' => 'favicon',
 'type' => 'upload' 
 );
answered Jul 1, 2012 at 17:33
Sign up to request clarification or add additional context in comments.

2 Comments

What about the extremely vague jquery("'.$option['id'].'").hide(); it has 2 errors on jQuery alone.
@Esailija That could easily be an extract of a coherent PHP statement, if you assume single quotes before and after the jQuery statement. I was presuming this is an extract of a longer statement.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.