How to modify firstChild property for FF?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • szimek

    How to modify firstChild property for FF?

    Hi!

    Like many others before recently I've found out that firstChild works
    little bit differently in IE and other browsers. I've got huge app
    that is currently IE only and used firstChild all over the place.
    Currently I wrote my own function firstNonTextChi ld(element), but it
    would be much more convenient for me to modify element.firstCh ild
    directly for FF and others, so I wouldn't have to change the code.

    The problem is that my current function looks like this:
    function firstNonTextChi ld(element) {
    var e = element.firstCh ild;
    // Fetch next element unless non-text node is fetched
    while(e.nodeTyp e == 3) {
    e = e.nextSibling;
    }
    return e;
    }
    As you can see it gets firstChild property itself. Is it possible to
    make an alias or something for the original firstChild property, so I
    could do
    HTMLElement.pro totype.firstChi ld = function() {
    ....
    element.origina lFirstChild;
    ....
    }
    And one more thing, my "solution" creates a method, not a property
    like the original firstChild. How can I modify this code to make
    modified firstChild a property and not a function?
  • webbugtrack@gmail.com

    #2
    Re: How to modify firstChild property for FF?

    [clipped]
    so I
    could do
    HTMLElement.pro totype.firstChi ld = function() {
    ...
    element.origina lFirstChild;
    ...}
    >
    And one more thing, my "solution" creates a method, not a property
    like the original firstChild. How can I modify this code to make
    modified firstChild a property and not a function?
    Your out of luck on this. It would be handy, but as you've noted you
    would need to prototype a method/property on the HTMLElement.

    This will work in some browsers, but IE is not one of them (even IE7).

    Issue: #186 Affects: IE5, IE5.5, IE6, IE7, IE8 Beta 1 MSIE Feedback ID: 333956 Description: The ability to prototype on any HTMLElement (...


    Your best bet at the moment, is to keep the function you have, or if
    you must, prototype the .firstChild property on Firefox only, to work
    like IE's implementation. However I would be extremely weary of doing
    this.

    Comment

    • szimek

      #3
      Re: How to modify firstChild property for FF?

      On 10 Lut, 03:21, webbugtr...@gma il.com wrote:
      [clipped]
      >
      so I
      could do
      HTMLElement.pro totype.firstChi ld = function() {
      ...
      element.origina lFirstChild;
      ...}
      >
      And one more thing, my "solution" creates a method, not aproperty
      like the original firstChild. How can I modify this code to make
      modified firstChild apropertyand not a function?
      >
      Your out of luck on this.  It would be handy, but as you've noted you
      would need to prototype a method/propertyon the HTMLElement.
      >
      This will work in some browsers, but IE is not one of them (even IE7).
      >
      http://webbugtrack.blogspot.com/2007...ototype-on-htm...
      >
      Your best bet at the moment, is to keep the function you have, or if
      you must, prototype the .firstChildprop ertyon Firefox only, to work
      like IE's implementation. However I would be extremely weary of doing
      this.
      Thanks for answering!
      Just one more question - how to make firstChild to be a property and
      not a function?

      Comment

      • Joost Diepenmaat

        #4
        Re: How to modify firstChild property for FF?

        szimek <szimek@gmail.c omwrites:
        Thanks for answering!
        Just one more question - how to make firstChild to be a property and
        not a function?
        In *mozilla only* <-- this means "for all intents and purposes
        completetly useless on the web", or *this may possibly work somewhere*:

        See defining getters and setters:

        <http://developer.mozilla.org/en/docs...ipt_1.5_Guide:
        Creating_New_Ob jects:Defining_ Getters_and_Set ters>

        Note that this will of course still call a method, it'll just look like
        it doesn't (which is fair enough).

        Note also (from that page):

        "Prior Firefox 3.0 getter and setter are not supported for DOM
        Elements. Older versions of Firefox silently fail."

        --
        Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

        Comment

        Working...