Where to store a "variable" in a <div>?

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

    Where to store a "variable" in a <div>?

    All,

    I'm currently using an alt attribute in a div tag to store "keywords"
    for a function that will show or hide certain div's based on a given
    keyword. Is there a better (standard) place to put these keywords?

    Code can be seen at http://www.straffin.com/test/DUdyn2.html . This is
    just a sample... the real "keywords" (and other information) will be
    pulled out of an XML file, not programatically generated.

    - Akbar
  • Lasse Reichstein Nielsen

    #2
    Re: Where to store a &quot;variable& quot; in a &lt;div&gt;?

    Akbar <me@here.com> writes:
    [color=blue]
    > I'm currently using an alt attribute in a div tag to store "keywords"
    > for a function that will show or hide certain div's based on a given
    > keyword. Is there a better (standard) place to put these keywords?[/color]

    That sounds like a job for "class". The class attribute value is a
    space-separated list of "class" names, and it is meant to distinguish
    equivalent elements based on the author's intentions.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Akbar

      #3
      Re: Where to store a &quot;variable& quot; in a &lt;div&gt;?

      On 12 Sep 2003 10:56:18 +0200, Lasse Reichstein Nielsen
      <lrn@hotpop.com > wrote:
      [color=blue]
      >Akbar <me@here.com> writes:
      >[color=green]
      >> I'm currently using an alt attribute in a div tag to store "keywords"
      >> for a function that will show or hide certain div's based on a given
      >> keyword. Is there a better (standard) place to put these keywords?[/color]
      >
      >That sounds like a job for "class". The class attribute value is a
      >space-separated list of "class" names, and it is meant to distinguish
      >equivalent elements based on the author's intentions.
      >
      >/L[/color]

      I've used "class" to assign CSS styles before... you also mean to tell
      me that you can assign multiple CSS styles with multiple classes?

      <style>
      .red { color : Red; }
      .bold { font-weight : bold; }
      </style>
      <p class="red bold">Wow!</p>

      (I just tried it... it works, in IE6 anyway.) Wow! Thanks!

      - Akbar

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Where to store a &quot;variable& quot; in a &lt;div&gt;?

        Akbar <me@here.com> writes:
        [color=blue]
        > I've used "class" to assign CSS styles before... you also mean to tell
        > me that you can assign multiple CSS styles with multiple classes?[/color]

        In a CSS 1 compliant browser, yes. Older browsers, like Netscape 4,
        have no support for CSS 2 (except where it matches CSS 1, and then
        it's still bad).
        [color=blue]
        > (I just tried it... it works, in IE6 anyway.) Wow! Thanks![/color]

        I wasn't sure it would work in IE6, since its CSS 2 support
        is also seriously lacking. Glad to see they have it.

        It should work in Mozilla and Opera, and probably most other
        recent browsers.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Code Ronin

          #5
          Re: Where to store a &quot;variable& quot; in a &lt;div&gt;?

          Akbar <me@here.com> wrote in message news:<emj2mv859 73h3g25gfmj7jpf eutm5gbgav@4ax. com>...[color=blue]
          > Is there a better (standard) place to put these keywords?[/color]

          No, I do not believe so. In fact, you are using "alt", which does have
          a standard usage and might cause side effects.

          The beauty of JavaScript is that you can dynamically add properties to
          any object, including HTML elements. You are not limited to the
          "published" attributes. (I do not believe you should use the published
          attributes, in fact, as your purpose does not match any of theirs.)

          Here are the lines I changed in your JavaScript in order to get the
          same effect (under IE6SP1, you will have to test the other browsers
          you support):

          1. Move the line [ var re = new RegExp(m, "g"); // Set up the match ]
          out of the for-loop. There is no reason to keep recreating the RegExp
          object.

          2. Change the line [ DOMobjDiv.alt = temptextone + " " + temptexttwo;
          ] to [ DOMobjDiv.keywo rds = temptextone + " " + temptexttwo; ]. Here,
          you have simply created a new, custom attribute "keywords" for your
          DIV element and assigned your keywords to it.

          3. Change the line [ var result = kids[i].alt.match(re); // Look for
          a match ] to [ var result = kids[i].keywords.match (re); // Look for a
          match ]. Here, you are searching the custom keywords attribute, rather
          than the alt attribute.

          Same effect, less chance for a name clash.

          Comment

          Working...