0

I am having some issues with getting the needed value from using $(this) within my code below:

....
open: function() {
    console.log('Popup is opened');
    console.log($(this).get(0).src);
},
....

I've also tried:

....
open: function() {
    console.log('Popup is opened');
    console.log($(this)[0].src);
},
....

But I do not seem to have the correct structor in order to get that value.

The objects of this are:

{
"0": {
    "isIE7": false,
    "isIE8": false,
    "isLowIE": false,
    "isAndroid": false,
    "isIOS": false,
    "supportsTransition": true,
    "probablyMobile": false,
    "popupsCache": {

    },
    "items": [{
        "el": {
            "0": {
                "jQuery111108245181320528183": 1
            },
            "context": {
                "jQuery111108245181320528183": 1
            },
            "length": 1
        },
        "src": "http://linkishere.com/Dolphin.jpg",
        "type": "image",
        "index": 0,
        "parsed": true,
        "img": {
            "0": {
                "jQuery111108245181320528183": 20
            },
            "context": {
                "jQuery111108245181320528183": 20
            },
            "length": 1
        },
        "hasSize": true,
        "preloaded": true
    }],
 Etc etc.....

What am I missing?

4 Answers 4

1

if you have above json structure then

use this["0"]["items"]["0"].src not $(this)[0].src

or

this[0].items[0].src
Sign up to request clarification or add additional context in comments.

Comments

0

your Item object contains src property and its belongs to Item then you should use

console.log(obj[0].items[0].src);

here is Fiddle Example

1 Comment

You got it. Thanks Anant!
0

use $(this).attr('src') not $(this)[0].src

Comments

0

if your this object is correct as you described. you can access src without jquery as follow:

 console.log(this[0].items[0].src);

2 Comments

TypeError: this[0] is undefined
your this object has some problem or your representation of this object is not correct. please try to log with console.log(JSON.stringify(this)); if code implementation is in jquery event scope, this object can confused with jquery object

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.