Page 1 of 1

How to change style on the fly ?

PostPosted: Mon Oct 26, 2015 1:54 pm
by David de Argentina
Hi all,

My NeoBook program load into an WebBrowser object a html file.
The html file has this style:

Code: Select all
  <style type="text/css">
    .iconfree {
      background-image: url('Pin_Violet2.png');
      text-align: center;
      color: White;
      font: arial, sans-serif;
      font-size: 14px;
      font-weight: bold;
    }
  </style>


I need change the color attribute (or another one) on the fly.

This action works fine at Chrome, FF, Opera... and IE9 or newer.
Code: Select all
BrowserExecScript "NavegadorWeb1" "document.getElementsByClassName('iconfree')[0].style.backgroundImage = 'url(Pin_Blue2.png)';" "JScript"


IE8 (browser component for Win XP) does not support getElementsByClassName method.

I need XP users can use this program.

Does any know how to change (via javascript or something else) this style on the fly and still work on IE8 ?

Thanks in advance,

David de Argentina

Re: How to change style on the fly ?

PostPosted: Mon Oct 26, 2015 4:01 pm
by David de Argentina
Jquery does the job.

Greetings !
David de Argentina

Re: How to change style on the fly ?

PostPosted: Mon Oct 26, 2015 4:11 pm
by Gaev
David de Argentina:

Yes, you can use jQuery ... but if this was the only reason for adding jQuery to your Application, you can consider these alternatives ...

1) This webpage ... http://stackoverflow.com/questions/6584 ... -ie6-ie7-i ... proivdes a solution.

2) Consider naming each element (id='1', id="2" etc. etc.) in your html ... then, you can select an element with something like ...

getElementById("7")

... which is supported by older Browsers as well.


BTW, for the benefit of others who seek similar solutions, post your jQuery code here.

Re: How to change style on the fly ?

PostPosted: Mon Oct 26, 2015 5:11 pm
by David de Argentina
Thanks Gaev,

But all elements were created using Javascript.
No ID or tag to search them normally.

Greetings,
David de Argentina

Re: How to change style on the fly ?

PostPosted: Mon Oct 26, 2015 9:50 pm
by Tony Kroos
So you don't have access to js code and cannot modify it?
David de Argentina wrote:No ID or tag to search them normally.

You always do have tags at runtime, otherwise it would not be a valid html document. Search google for "traversing DOM tree" and "parent/child elements".