Linas
Linas

Reputation: 4408

Get image link from child element

I'm new with colorbox, and so far everything looks fine but i would like to get href from child element. So let's say i have div and a inside of that div:

<div id="colorbox">
   <a id="image" href="image.jpg">img</a>
</div>

And now i'm using basic function:

$("#colorbox").colorbox();

So ofc it won't work so iv'e tried to do it like this:

$("#colorbox").colorbox({inline:true, href:"#image"});

And it only messed everything up, how else can i get path to my image?

Btw in my page it's going to be a lot of div with images all of them going to have same id

Upvotes: 0

Views: 287

Answers (1)

Chibuzo
Chibuzo

Reputation: 6117

First, you should not have multiple samples a tag with the same id, id's should be unique, you can use class instead if your elements must have the same identifier.

From your code sample, you can get the href value like this

var imgHref = $('#colorbox').find('a#image').attr('href'); 

there are many ways to get it though.

Upvotes: 1

Related Questions