/    Sign up×
Community /Pin to ProfileBookmark

if(document.getElementsByName(c).background.indexOf(‘../bin/sort.jpg’)!=-1)

if(document.getElementsByName(c).background.indexOf(‘../bin/sort.jpg’)!=-1)

why this not working 😑

to post a comment
JavaScript

14 Comments(s) ↴

Copy linkTweet thisAlerts:
@Mr_JFeb 19.2006 β€”Β How have you applied the background?

Maybe you need

if(document.getElementsByName(c).style.backgroundImage.indexOf('../bin/sort.jpg')!=-1)
Copy linkTweet thisAlerts:
@gert_cuykensauthorFeb 19.2006 β€”Β Aleloia it works ?
Copy linkTweet thisAlerts:
@gert_cuykensauthorFeb 19.2006 β€”Β wait a minute it doesnt work :mad:

<td name=0 class=header onclick=sc(0);>servers</td>

Error: document.getElementsByName("0").backgroundImage has no properties
Copy linkTweet thisAlerts:
@Mr_JFeb 19.2006 β€”Β I think you are using the wrong method by using

document.getElementsByName

it should be

document.getElementById

Give your td cell an ID and try

if(document.getElementById(c).style.backgroundImage.indexOf('../bin/sort.jpg')!=-1)

Something else you could try

if(document.getElementById(c).currentStyle.backgroundImage.indexOf('../bin/sort.jpg')!=-1) - for IE

if(document.defaultView.getComputedStyle(document.getElementById(c), '').getPropertyValue("background-image").indexOf('../bin/sort.jpg')!=-1) - for Mozilla
Copy linkTweet thisAlerts:
@MstrBobFeb 20.2006 β€”Β If you are using getElementsByName, it will return an array. So if you want the first element, use:

<i>
</i>if(document.getElementsByName(c)[0].style.backgroundImage.indexOf('../bin/sort.jpg')!=-1)
Copy linkTweet thisAlerts:
@gert_cuykensauthorFeb 20.2006 β€”Β [code=php]document.getElementsByName(c)[0].backgroundImage has no properties[/code]

grrrr... is there no javascript code that can print the dom structure of my page
Copy linkTweet thisAlerts:
@gert_cuykensauthorFeb 20.2006 β€”Β o o wait a minute could it be that i forgot ".style." ?
Copy linkTweet thisAlerts:
@Mr_JFeb 20.2006 β€”Β You mean as per my first reply ?
Copy linkTweet thisAlerts:
@gert_cuykensauthorFeb 20.2006 β€”Β eeeeuh no , look a bird (need a running away smily)
Copy linkTweet thisAlerts:
@MstrBobFeb 20.2006 β€”Β [code=php]document.getElementsByName(c)[0].backgroundImage has no properties[/code]

grrrr... is there no javascript code that can print the dom structure of my page[/QUOTE]


If you use Firefox, the DOM Inspector tool will show you that.
Copy linkTweet thisAlerts:
@gert_cuykensauthorFeb 20.2006 β€”Β my firefox 107 doesnt have a DOM inspectore in the tools menu ? Where can i find it ?
Copy linkTweet thisAlerts:
@gert_cuykensauthorFeb 20.2006 β€”Β ok i found a DOMI now how do i see whats the right DOM path of a element ? I can only see the atributes and property's of a DOM node ?
Copy linkTweet thisAlerts:
@gert_cuykensauthorFeb 20.2006 β€”Β this works
[code=php] if(document.getElementsByName(c)[0].style.backgroundImage.indexOf('url(../bin/sort.jpg)')!=-1)
{document.getElementsByName(c)[0].style.backgroundImage='url(../bin/down.jpg)'}[/code]


But it doesnt actualy change the background you are seeing but only the value, does anybody know the DOM path to change background ?
Copy linkTweet thisAlerts:
@MstrBobFeb 20.2006 β€”Β The left pane of DOM Inspector shows you the DOM tree. If you press the '+' button next to a node, it shows you all of the children of that node.

You don't, I believe, need the url() bit for background image. so:

[code=html]

if(document.getElementsByName(c)[0].style.backgroundImage.indexOf('../bin/sort.jpg')!=-1)
{document.getElementsByName(c)[0].style.backgroundImage='../bin/down.jpg'}
[/code]
Γ—

Success!

Help @gert_cuykens spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 β€” BETA 5.18,
whats_new: community page,
up_next: more Davinciβ€’003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinciβ€’003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...