How to add Javascript(jQuery) to a page created from XSLT/XML -


i have xml file (consisting of few data items, namely <book> ) , corresponding xslt file created, when opened in browser turns list of books html table. columns named "author", "title", , "bookid" (they ids of child nodes of <tr>).

now want make resulting page dynamic using jquery, i.e. want make resulting table rows sorted on column click on. however, while table renders fine, resulting jquery code seems have no effect.

i not sure whether result of bugs in jquery code, or whether didn't include properly, or both. included 2 <script></script> tags in xsl file (one hotlink jquery library, other link code), i'm not sure if correct way it. also, can on jquery code find out if there's wrong (i'm complete newbie web programming, please forgive errors)?

thanks!

$(document).ready(function() {  function sortby(a, b, selectfunction) {     var a1 = selectfunction(a);     var b1 = selectfunction(b);      if (a1 < b1) {         return -1;     }     if (a1 > b1) {         return 1;     }     return 0; }  function sorthelper(index) {     var rows = $('table tbody tr').get();     rows.sort(function(a, b) {         return sortby(a, b, function(x) { return $(x).children('td').eq(index).text().touppercase(); });     });     rows.appendto('tbody'); }  $('#author').click(function() {    sorthelper(0); });  $('#title').click(function() {     sorthelper(1); });  $('#bookid').click(function() {     sorthelper(2); });  }); 

a stated in comments .get() returns javascript object. use rows.sort() want jquery object.

// javascript $(obj).get(0); // returns first element query // jquery $(obj).eq(0); // return first $(element) query. 

also 1 thing noticed: since you're accessing td's id can like:

var toprow = $("table tbody tr").eq(0),     topcells = toprow.find("td"); // expecting #author, #title, #bookid  topcells.click(function(){     sorthelper($(this).index()); // makes more sense way }); 

other if you're loading external *.js files solution you'll fine. if you're inserting code directly page use cdata encoding described here.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -