how can I access a css class from the appended html div?

Tags: javascript,jquery,html,css

Problem :

How can I access a css class created by jquery's append. I tried the following code with a click listener on my class I want to access in the div but the event is not being picked up. Thank you

$.each(items, function(i, item) {
  $("#bookedAds").append("<div class='alert alert-info' role='alert'>"+

    item.clientName+" <button name=' "+item.clientName +
    "' class='btn quickview' id='quickview' adSize ='"+item.adSize +
    "'>Quick View</button></div>"

//Below is my on click Listener

  alert("This is not popping up :(");

Solution :

To trigger your event on dynamically created elements you need to use event delegation.

you can try updating your code like this

$(document).on('click', '.quickview', function(){ 
    alert("This is popping up :)");

hope this helps.

    CSS Howto..

    How can I style external links like Wikipedia?

    How to make Gravity Forms Responsive (left/right )?

    How to change the background colour of a QWidget inside QStackedWidget using css?

    How can I register a css page from an ascx control?

    How to make a rectangle mask with css

    How to align a div with the right of a table?

    Simple CSS: How to fix display:inline issue

    How to display (
  • ) menu items over divs - z-index not working
  • How to access the set qt stylesheet properties (css like grammar), or is there an css to xml converter?

    How to Over ride youtube external style?

    how to disable the highlighting view on selection either in html or css?

    How to override a display:none property applied to parent element in specific child elements

    Flexbox and Bootstrap How to Put Image in Navbar Brand Area

    How can display table-row behave like colspan=3

    How to remove gap in masonry?

    How to change font size for safari and opera but not chrome in CSS file.

    How to center banner with jquery mobile?

    How to align the menu to center after certain width media query fires for RWD

    how to resolve border-radius property issue in all versions of browsers? [duplicate]

    how to make “before” li is fixed at the bottom of li?

    How to add multiple CSS styles to an element with .css()

    How to apply CSS to anchor with active class only (parent only) and not include children?

    How to remove mystery indents in a form?

    How can I adjust this carousel to only pause when user mouses over one of the boxes?

    css how to align absolute positioned child element to the right of fluid width parent

    How to add JS and CSS file in web page based on parameter?

    How to eliminate an annoying blue line in a border area of a hyperlink / h2 class with CSS

    How can I get this style effectv with css or jquery?

    How to create a

    How to asynchronously load CSS using jQuery?