0

webkit browser is not supported "ruby of justify".

I found this javascript (https://code.google.com/p/justify/).

As a result of using this, a new problem has occurred...

 &ltul id="list"&gt
  &ltli&gt
   &lth3 id="main"&gt&ltruby&gtLorem&ltrt id="sub"&gtIpsum&lt/rt&gt&lt/ruby&gt&lt/h3&gt
   &ltp&gtLorem ipsum dolor sit amet...... &lt/p&gt
  &lt/li&gt
 &lt/ul&gt

This is fine. But this script used "document.getElementById".

When the element is increased, of course, it does not work.

When I rewrite "document.getElementById" to "document.getElementsByClass", Uncaught TypeError: Object #<NodeList> has no method...

When the element is increased, what I do I do?

(Sorry... I'm not good at English)

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
  • What do yo mean by element is increased? do you mean you have more than one ` – Vaishak Suresh Jul 31 '13 at 23:53
  • I think you mean `document.getElementsByClassName`... – giaour Jul 31 '13 at 23:58
  • Please show us your javascript code that throws this error! Else I can only guess that you've got the same problem as in [getElementByClass().setAttribute doesn't work](http://stackoverflow.com/questions/2565909/getelementbyclass-setattribute-doesnt-work). – Bergi Aug 01 '13 at 00:00
  • Thanks everyone. I relearn from English... Maybe I understand that Is not being captured in dom – John Carter Aug 01 '13 at 01:18

1 Answers1

1
Uncaught TypeError: Object #<NodeList> has no method...

This error occurs because you are trying to treat a list of nodes like a single node. Probably because you are forgetting to get an element out of the result of getElementsByClassName.

getElementById returns a single DOM element, but getElementsByClassName returns a list (array-like object) of DOM elements. You have to index into the latter, but not the former.

<div class="foo" id="bar"></div>

<script>
alert(
    document.getElementById('bar')   // One result at most, so no [0].
    ===
    // ClassName, not Class.  [0] since the result is a list.
    document.getElementsByClassName('foo')[0]
);
</script>

should alert "true"

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245