Is it possible to get an element from the value of the “src” attribute?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no DOM method to filter elements by attributes. You need to go through all the elements of a particular tag and filter out those with a matching
srcvalue:The
nodesarray will contain all theimgelements with asrcattribute that has a valueimage.png.UPDATE:
Further to the comment below, keep in mind that there might be more than one element with the same
srcvalue. That is why the function above returns an array.You can use the
element.setAttribute()method to change the value of an attribute: