This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Modern JavaScript for the Impatient and have Cay Horstmann on-line!
See this thread for details.
Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Executing javascript on div loaded by php call - ajax tabs

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I am using Jquery tabs. One of these tabs calls it's content through ajax by referring to a PHP function that returns the HTML table code for a query I'm doing on a database using codeigniter.

Now I would like to call the jquery widget "tablesorter" on that table.

In a simple case I would just call the js on the div id of the table ("#myTable").tablesorter();

But now since the content is called via ajax there's no existing div id to call to with tablesorter...

Any ideas... ?

Thanks!
 
Marshal
Posts: 67445
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can execute the code in the complete callback of the Ajax request, at which time the element will exist.
 
Ranch Hand
Posts: 58
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try (".myTable").tablesorter(); on class instead of table id.
It worked in my case.
 
Bear Bibeault
Marshal
Posts: 67445
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

K West wrote:Try (".myTable").tablesorter(); on class instead of table id. It worked in my case.


If myTable is the id, which we have no inkling is not the case, what could this possibly accomplish? As indicated by the poster, the isuue is that the code can't be executed until after the element is created.
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic