0

I've got a page where I'm trying to fetch data using ajax and append it to a html table dynamically. Everything works fine but for one of the columns where i'm trying to style a link as a jquery button. I use the same css class for the button across the application and it works just fine in all other places. Just on the dynamically added row, the link shows up as a plain link instead of getting sytled as a jquery button.

3
  • Here is the fiddle on what i'm trying to do: jsfiddle.net/bobm76/FwyR2 Commented Feb 19, 2014 at 1:25
  • In your JSFiddle, the "Click me" button with the "jqbutton" class is styled for me, on all the dynamically added rows. I'm in Chrome 32 Commented Feb 19, 2014 at 1:28
  • Interesting. I'm also on chrome 32 and it did not work for me till i incorporated the changes like in the answers below. I had updated my fiddle just a few minutes ago to include the extra line, without which the button is not styled. Commented Feb 19, 2014 at 1:57

2 Answers 2

1

You should place this

 $(".jqbutton").button();

into the click event handler function as well.

$("#test").click(function(){
    console.log("button clicked");
    $('<tr>').append(
        $('<td>').text('Test data x'),
        $('<td>').text('Test data y'),
        $('<td>').text('Test data z'),           
        $('<td>').html('<a href="#" class="jqbutton">Click me</a>')
    ).appendTo('#testtable');
    $(".jqbutton").button();
});
Sign up to request clarification or add additional context in comments.

Comments

1

use .button() method inside click

$(function(){
    $(".jqbutton").button();

    $("#test").click(function(){
        console.log("button clicked");
        $('<tr>').append(
            $('<td>').text('Test data x'),
            $('<td>').text('Test data y'),
            $('<td>').text('Test data z'),           
            $('<td>').html('<a id="test" class="jqbutton">Click me</a>')
        ).appendTo('#testtable');
        $(".jqbutton").button();

    });
});

Link to Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.