D
D
dobriykot2010-12-06 17:26:32
JavaScript
dobriykot, 2010-12-06 17:26:32

jQuery UI Dialog, how to hang an event on click of a link inside it?

Now the code looks like this:

<br>
<div id="address-wrapper"><br>
  <a id="address-select" href="#" title="Нажми">Нажми</a><br>
</div><br>
<br>
<div id="dialog-form" title="Выберите ваш город">	<br>
  <label for="search">Поиск</label><br>
  <input type="text" name="search" id="search" class="text ui-widget-content ui-corner-all" /><br>
  <input type="button" name="post" id="search-button" value="Поиск" />		<br>
  <br /><br /><br>
  <div id="results"></div><br>
</div><br>
<br>
<script type="text/javascript">	<br>
  function searchSubmit() {<br>
  $.ajax({ type: "POST", <br>
     url: "gni_ajax.asp", <br>
     data: "query=" + $("#search").val(),<br>
     success: function(data){<br>
                                      $("#results").empty();<br>
          $("#results").append(data);<br>
          return false;} <br>
     });<br>
  };<br>
  <br>
  $('#search').keypress(function(event) {<br>
      if (event.keyCode == '13') {<br>
    searchSubmit();<br>
      }		   <br>
  });<br>
  <br>
  $("#search-button").click(function () { searchSubmit(); });<br>
      <br>
  $("#dialog-form").dialog({<br>
    autoOpen: false,<br>
    height: 400,<br>
    width: 400,<br>
    modal: true,<br>
    buttons: {				<br>
      "Отмена": function() {<br>
        $( this ).dialog("close");<br>
      }<br>
    },<br>
    close: function() {<br>
      alert("i'm closing!");<br>
    }<br>
  });<br>
<br>
  $("#address-select").click(function() {<br>
    $( "#dialog-form" ).dialog( "open" );<br>
  });<br>
  <br>
  $(".addr").click(function() {<br>
    alert($(this).text());<br>
    alert(this.id);<br>
<br>
    $("#dialog-form").dialog("close");<br>
  });<br>
  <br>
</script><br>


It was necessary for me that when I click on one of the links returned by Ajax (different numeric id and texts, one .addr class, its text and values ​​are inserted into the input. But I could not achieve this. I decided to at least see what alert would give. But he didn’t show that either, there was no reaction to clicking. If I hang an event on pressing address-select, then everything works fine. But these links inside the dialog that don’t work. Not like an alert, but the dialog itself doesn’t close Even if you specify not ".addr", but simply "a" Checked in firebug, the elements are created normally:
<br>
<a href="#" id="7700000000000" class="addr">Москва г</a><br>

What to do with it? After all, it should work!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Lomakin, 2010-12-06
@t0H

for hanging events on elements that do not yet exist, there is this bind and live

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question