Forum Bugs

javascript generated <li> not working

facboy
hi,

I'm generating <li>s in a <ul> using javascript, and they don't render correctly in the resulting text. Hard-coded <li>s in the same list work fine. I'd expect something like:
  • hard-coded item 1
  • generated item 1
  • generated item 2

but instead i get:

  • hard-coded item 1
  • generated item 1generated item 2

(I'm not sure about whether they have the leading bullet points as my list doesn't have these).

to provide some context, i'm trying to generate a table of contents using javascript. other problems i've noticed are that the links <a> generated by javascript aren't actually rendered as links in the pdf, unlike hard-coded links which are rendered as links in the pdf.

Edited by facboy

mikeday
This could be a namespace issue. In Prince 8.1, document.createElement creates elements that are not in any namespace. This may result in default styles not applying if the rest of the document is in the XHTML namespace.

We have fixed this issue for the next release of Prince, but a possible workaround in the meantime might be to use document.createElementNS, like this:
document.createElementNS("http://www.w3.org/1999/xhtml", "li")
facboy
thanks mike. actually i found using the html5 parser made it work fine as well, with the bonus that i could use jquery. btw it seems versions of jquery > 1.8.x don't work.

one other question, with something like

content: target-counter(attr(href), h1)

is it possible to use attr on eg the parent element? if for eg you were applying the content to a <span> inside a link.
mikeday
Not directly, but you could use string-set on the parent element to capture the value in a named string, and then reference that string in the content for the child element. In fact, I don't think I've ever actually done that, so it might be worth trying. :)
mikeday
Prince 9 is now available, which fixes the document.createElement issue and supports jQuery 1.9.