Dynamic link html table contents

Xerox Shah

I am new to jQuery. I have table contents displayed by jQuery using Bootstrap. I want to hyperlink for each value to be link to url. I don't know how to embed jQuery inside another jQuery to make this happen. I used [href= "www.google.com/" + run_accession> run_accession ] but this doesn't take run_accession parameter.

<table id="resultsTable" class="table table-hover">
<thead>
    <tr><th><input type="checkbox" id="selectAll" checked="true" \></th>
    <th class="sortable" sort-target="run_accession">Run</th>
    <th class="sortable" sort-target="experiment_accession">Experiment</th>

</thead>
<tbody id="results_display">
{% for sra in sra_page %}
<tr><td><input class="srasCb" checked="true" type="checkbox" name="sras" value="{{ sra.run_accession}}"\></td>
    <td>{{ sra.run_accession }}</td>
    <td>{{ sra.experiment_accession }}</td>
</tr>
{% endfor %}

<script>
var propagate_table = function(data) {
    $('#results_display').empty();

 for (i = 0; i < data.length; i++) {            

        $('#results_display').append('<tr><td> <input class = "srasCb"'
            + checkboxSelection +' type="checkbox" name="sras" value="' + run_accession +'"\></td><td>'
           // I want to make <td> as link to url as: www.example.com/data[i].fields.run_accession 
            +  data[i].fields.run_accession; + '</td><td>'
            + data[i].fields.experiment_accession + '</td><td>'
         );
      }
 }
</script>

Would highly appreciate your suggestions.

CrowbarKZ

To make <td> behave as a link you can create <td> elements using jQuery constructor inside your for loop and attach click event listeners to them, something like this:

var container = $('#results_display');

for (i = 0; i < data.length; i++) { 

    // create elements using jquery
    var tr = $('<tr/>');
    var td1 = $('<td/>', {
        text: 'cell 1'
    });
    var td2 = $('<td/>', {
        text: 'cell 2'
    });

    // add click event listener to td1
    td1.click(function () {

        // go to url on click
        window.location.href = "http://google.com";
    });

    // append elements to container
    td1.appendTo(tr);
    td2.appendTo(tr);        
    tr.appendTo(container);
}

Here is jQuery documentation about creating elements http://api.jquery.com/jquery/#jQuery-html-ownerDocument

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Creating dynamic table of contents in ReactJS

From Dev

html::link to dynamic route

From Dev

Change table contents depending on link clicked

From Dev

Pandoc HTML Table of Contents Output

From Dev

Table of Contents with dotted underline in html

From Dev

Scrollable table contents html/css

From Dev

Table of Contents Page with Dynamic Page Numbers

From Dev

Dynamic Array in table HTML

From Dev

Dynamic table HTML Javascript

From Dev

Dynamic html table with django

From Dev

XPath for HTML table cell contents starting from given contents

From Dev

Dynamic Table: Link button to textbox cell by cell

From Dev

Dynamic "enquiry" link based on data in table row

From Dev

Dynamic HTML using Javascript: Fill same HTML object with different contents

From Dev

Writing full contents of Pandas dataframe to HTML table

From Dev

Make HTML table expand to hold contents with no wrapping

From Dev

Relocating a column and its Contents in HTML table layout

From Dev

how to extract HTML table contents to DataTable

From Dev

Prevent HTML table from resizing to fit contents

From Dev

HTML Table, Right Justify Cell (Not Contents)

From Dev

how to extract HTML table contents to DataTable

From Dev

How to remove epub table of contents link to title page created by pandoc

From Dev

DITA XML: How can I add a link to the table of contents?

From Dev

Dynamic query results to HTML table

From Dev

dynamic html table with complex JSON

From Dev

Dynamic & Complex rowspan in HTML table

From Dev

Width differences in dynamic html table

From Dev

Dynamic HTML Table in PHP Mail

From Dev

dynamic html table with complex JSON

Related Related

HotTag

Archive