0

I'm trying to define a few events and styles for elements that will be dynamically added to the DOM based on user interaction with the application. I see that the live() method can be used for the events but I can't figure out how to apply the styles and more specifically rules like the one below using the live() method.

$('a.button').button(); //jquery-ui call to turn links into cool buttons
David Tang
  • 92,262
  • 30
  • 167
  • 149
jjr2527
  • 440
  • 1
  • 6
  • 16

3 Answers3

0

The concept is to create a custom event say buttonCreatedEvent. The event is triggerred if a button is created(using the trigger() function). You can bind the event using live(). In the callback function of live() then you can tell the script to create the jqueryui button.

Quincy
  • 4,393
  • 3
  • 26
  • 40
0

The better way would be to use css for this and not javascript, that way anything you add dynamically will automatically have the right style.

Martin Jespersen
  • 25,743
  • 8
  • 56
  • 68
0
$('a').addClass('mycoolclass')

http://api.jquery.com/addClass/

.mycoolclass {
  display:block;
  border: solid 1px black;
  padding:10px;
  background: #CCC;
  color: black;
  text-decoration: none;
}

This would make all your a's look like black and white custom buttons or something.

Techism
  • 534
  • 3
  • 11