0

I'm trying to access an element's attribute value, by finding a different attribute, by name, of that same element.

Here's some code:

<option data-img-src="http://example.com/pic.jpg" value="Pool Party 21" pdf-data="http://example.com/myPDF.pdf"></option> <img class="image_picker_image" src="http://example.com/pic.jpg"> 

Here's some PHP where I try to get the SRC of that image, store as a variable. Then, try to find another element where the SRC of the image (the previously stored variable) is an attribute called data-img-src that holds that value.

Finally, I try to store that found-elements attribute called "pdf-data" as a string in another variable.

pdfbgImage = $('.tab-pane.active div.thumbnail.selected').children('img').attr('src'); pdfURL = $("[data-img-src=pdfbgImage]").attr('pdf-data'); 

I don't believe my code is right. Can anyone help?

1 Answer 1

2

You have to concatenate the first variable into the second selector

var pdfbgImage = $('.tab-pane.active div.thumbnail.selected').children('img').attr('src'); var pdfURL = $("[data-img-src='"+pdfbgImage+"']").attr('pdf-data'); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.