compatibility problems with javascript

Home Forums Product Support Forums Ajax Search Pro for WordPress Support compatibility problems with javascript

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 4 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18680
    danielastorga
    danielastorga
    Participant

    I want to make a customization with jquery.
    I have already customized other parts of my site with jquery and everything is going well.
    I want to move the mouse over any of the search results and I would like something like this:
    see attached fig.1.

    I know that the support does not include customizations.
    however, I think there is a conflict when I try to add a simple event like the example:

    $(“.overlap”).mouseover(function(){

    $(this).css(“background-color”,”red”);

    });

    This code is included in a js file duly registered in wordpress.
    I do not know what may be happening.
    Can you help me?
    Thank you

    Attachments:
    You must be logged in to view attached files.
    #18685
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    The issue is, that the ajax results are considered as dynamically generated/inserted elements on the DOM node tree. Your code however will only work with items, that are present at the page load. You need a dynamic event binding function.

    To correctly attach a handler, you need to use the jQuery.fn.on(..) function. In your case, something like this:

    If I may recommend an alternative solution. Changing colors is much simpler by using custom CSS. In your case:

    .asp_r .overlap:hover {
      background-color: red;
    }

    That is much simpler in my opinion 🙂

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.