R
R
rejjer2015-04-06 06:25:20
Node.js
rejjer, 2015-04-06 06:25:20

Is it possible to make a "dynamic" jQuery selector?

the plugin works like this:

$(function(){
$('#editable').editable('click', function(e){
    console.log(e.value);
  });
});

<span id="editable">Текст </span>
in order for it to work correctly, it is necessary that the selector be unique, otherwise there will be jambs.
I want to apply it to a table:
<table class="editable">
  <tr>
    <td id="t-1-1">Текст</td>
    <td id="t-1-2">Текст</td>
  </tr>
  <tr>
    <td id="t-2-1">Текст</td>
    <td id="t-2-2">Текст</td>
  </tr>
  <tr>
    <td id="t-3-1">Текст</td>
    <td id="t-3-2">Текст</td>
  </tr>
</table>

I have to write too much:
$(function(){
  $('.editable #t-1-1').editable('click', function(e){
    console.log(e.value);
    });
  $('.editable #t-1-2').editable('click', function(e){
    console.log(e.value);
    });
  $('.editable #t-2-1').editable('click', function(e){
    console.log(e.value);
    });
  $('.editable #t-2-2').editable('click', function(e){
    console.log(e.value);
    });
  $('.editable #t-3-1').editable('click', function(e){
    console.log(e.value);
    });
  $('.editable #t-3-2').editable('click', function(e){
    console.log(e.value);
    });
});


I don't really know jquery, but I think it should somehow be simplified ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
olamedia., 2015-04-06
@w999d

.editable td
.editable *[id]

K
kvityasya, 2015-04-06
@kvityasya

$('.editable td').editable('click', function(e){
console.log(e.value);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question