Table And this is the B" /> Table And this is the B" /> Table And this is the B"/>

Using Brython to add hyperlinks to HTML table

69 views Asked by At

I'm trying to add a hyperlink to the elements in the first column in Brython-HTML:

This is the HTML part:

<div id="zone">Table</div>

And this is the Brython part:

        <script type="text/python" id="script7">

        from browser import document
        from browser.html import TABLE, TR, TH, TD
        table = TABLE()
        row = TR() # create a row
        # add header cells
        row <= TH("Header1")
        row <= TH("Header2")
        table <= row # add the row to the table

        lines = [ ['Morrissey','vocals'],
        ['Johnny Marr','guitar'],
        ['Mike Joyce','the drums'],
        ['Andy Rourke','the bass guitar']
        ]
        
        for line in lines:
            table <= TR(TD(line[0], href='http://www.python.org')+TD(line[1]))

        document['zone'].text = ''
        document['zone'] <= table


        </script>

I can see the table in the browser, but there is no hyperlink to click and open the page.

enter image description here

Any help would be appreciated.

Regards, Behrouz

1

There are 1 answers

0
Behrouz Beheshti On

I solved it by changing

table <= TR(TD(line[0], href='http://www.python.org')+TD(line[1]))

to

table <= TR(A(line[0], href='http://www.python.org')+TD(line[1]))

Now it looks like:

enter image description here