P
P
pvgdrk2015-06-04 23:51:00
JavaScript
pvgdrk, 2015-06-04 23:51:00

How to bind a click event to an element using ajax?

function getDataForDiv(){
        var url = "/getDataForDiv/";
        $.ajax({
            async: true,
            type: 'POST',
            url: url,
            dataType: 'json',
            success: function(data){
                $('#someDiv').click(function(){
                    alert(data)
                });
            }
        });
    }


Ayakosm getting data for the diva. It is necessary to display the value of data when clicking on the div. How to do it? The solutions with on and live didn't work. Perhaps he did something wrong.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-08-08
@Shimpanze

if (e.attributes[i].nodeName !== 'href' && e.attributes[i].nodeName !== 'src') {

G
Gleb Starkov, 2018-08-08
@colonel

... || 'src'
Will always be true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question