views:

156

answers:

3

I am busy writing a simple Adobe Air app using HTML, jQuery and some jQuery plugin to load RSS feeds.

The problem I am having is that I am generating a section of HTML components (buttons) so that I can execute specific code on button click. But when the page is displayed the button never executes; I have tried using the built-in log function as well as alert, but none of them execute. The weird part is when I copy the HTML component into a part of the page that is not generated it executes fine.

I insert the following into a div using jQuery and it does not execute.

'<input type="button" onclick="LoadPage()" value="Test" />'

If I just insert it into the HTML it works fine.
I am using version 1.3.2 of jQuery; I am also using this plugin to load the data into a div, and I have modified line 82 to include the html component above.

I should note that when I inspect the page using AIR's introspector the HTML is valid.

What could be going wrong?

A: 

If you want to use jquery to handle the click you can use the live event.

I also had that problem some time ago, and this solved the problem.

If you give your button an id would look something like this:

$("#YourButtonId").live("click", function (){....
fmsf
A: 

Got the same problem with 'onClick' instead of 'onclick' ? Also check if the function isn't called 'Loadpage' instead of 'LoadPage'.

I sometimes have case sensitive problems in javascript, not sure if it are functions that are case sensitive.

Thomas Stock
+2  A: 

I don't see the problem. The following works fine for me:

$(document).ready(function() {
  $('#mainDiv').html('<input type="button" onclick="LoadPage()" value="Test" />');
});

function LoadPage()
{
  alert("Hello");
}
samjudson
I've also tested it like that and yup it does work +1
fmsf
Hi ,the component was being added in the rss plugin (my wording was vague) , i think the problem is in the way it generates the html in the plugin
RC1140