Jump to content

getAttribute: Style.backgroundImage?


tinfanide

Recommended Posts

<tr style="background-image: url("background-image.jpg")"></tr>

I wonder how we can get the attribute (url).I'm not sure about it.

document.getElementsByTagName("tr").getAttribute("style.backgroundImage");

Link to comment
Share on other sites

1. getElementsByTagName returns a collection, not an element. To access a member of the collection you need an index, like an array index. If you know the index, then its easy. If not, then you need to loop through the collection and search each item for another distinctive property. 2. I'm pretty sure getAttribute returns a single attribute, not an attribute of an attribute. This will work if you want the backgroundImage of the first <tr> :

document.getElementsByTagName("tr")[0].style.backgroundImage;

Link to comment
Share on other sites

IF using bytagname you have to identify which tr you are targettingdocument.getElementsByTagName("tr")[n] where n represent the index position it is located at, starting from 0.You use getAttribute("style.backgroundImage"); as getAttribute("style");, but this will return "background-image: url('background-image.jpg')" (corrected double quote conflict), it would be better to use .style.backgroundImage as in document.getElementsByTagName("tr")[n].style.backgroundImage, which return 'url("../and_and1.png")', where can maybe use slice to remove url and brackets.

Link to comment
Share on other sites

Sorry to both who've answered me.I should have shown you the whole codes instead of the one that is wrong and that was just typed by me in the example.

Sub a()Dim oIE As SHDocVw.InternetExplorerSet oIE = New SHDocVw.InternetExplorerDim oHTML As HTMLDocumentoIE.Visible = TrueoIE.navigate "http://www.website.com/"While oIE.Busy    DoEventsWendSet oHTML = oIE.documentDim oTr As HTMLTableRowFor Each oTr In oHTML.getElementsByTagName("tr")''' return Null    Debug.Print oTr.getAttribute("Style.backgroundImage")Next oTr End Sub

I think I should have posted it in the VBA forum. Well, but sorry I have started it here.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...