Jump to content

getAttribute: Style.backgroundImage?


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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...