Solved

Jquery button help

Posted on 2011-03-02
3
251 Views
Last Modified: 2012-06-27
Hi

Im trying to create dynamic table which will insert row to end of the table and row contains a jquery button

row adding works fine. but button not working

i guess its because im adding button after document ready.

how to fix this problem?
0
Comment
Question by:3xtr3m3d
  • 2
3 Comments
 
LVL 2

Expert Comment

by:mhmr
ID: 35020644
Hello
you can try like this :

	
<div id="mydiv">
</div>
<script> 
$("#mydiv").append('<table><tr><td>I Am The 1st</td></tr><tr><td><button id="btn">am a button</button></td></tr></table>');
$("#btn").live ( "click" , function () { alert('you pressed me??'); } );
</script>

Open in new window

0
 
LVL 3

Author Comment

by:3xtr3m3d
ID: 35034303
Hi

Thanks for reply and buttons now working but created  button is just a button and is it possible to change created button back to a jquery ui button?

current code is

$(document).ready(function() {

	$( '.Eb1' ).button({
		icons: {
			primary: "ui-icon-arrowthick-1-w"
		},
		text: false
	})
	.click(function() {
		$("#mydiv").append('<table><tr><td>I Am The 1st</td></tr><tr><td><button id="btn">am a button</button></td></tr></table>');
	});
	
					
	$("#btn").live ( "click" , function () { 
		alert('you pressed me??');
	});

});

Open in new window


<div id="mydiv"></div>
<button class="Eb1">add</button>

Open in new window

0
 
LVL 2

Accepted Solution

by:
mhmr earned 500 total points
ID: 35037699
yes you can do it like this
	$(document).ready(function() { 
	$( '.Eb1' ).button({  
		icons: {
			primary: "ui-icon-arrowthick-1-w"
		},
		text: false
	})
	.click(function() {
		$("#mydiv").append('<table><tr><td>I Am The 1st</td></tr><tr><td><button id="btn">i am a button</button></td></tr></table>');
		$("#btn").button({  
			icons: {
				primary: "ui-icon-arrowthick-1-w"
			},
			text: false
		}
		).click(function () {
			alert('you pressed me??');
		});
	});					

	});

Open in new window

<div id="mydiv"></div>
<button class="Eb1">add</button>

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now