Reputation: 7153
I want to make three different labels editable when I click on a single href
I have:
<tr>
<td align="left">PLZ:</td>
<td>
<label for="name" class="control-label">
<p class="text-info">
<label style="color: #662819;" id="plz"></label>
<i class="icon-star"></i>
</p>
</label>
<input type="text" class="edit-input" />
<div class="controls">
<a class="edit" href="#">Daten sichern</a>
</div>
</td>
</tr>
changing this one label with:
CSS:
.edit-input {
display:none;
}
JQuery:
$(function() {
$('a.edit').on("click", function(e) {
e.preventDefault();
var dad = $(this).parent().parent();
var lbl = dad.find('label');
lbl.hide();
dad.find('input[type="text"]').val(lbl.text()).show().focus();
});
$('input[type=text]').focusout(function() {
var dad = $(this).parent();
$(this).hide();
dad.find('label').text(this.value).show();
});
});
how to do it for 2 or more labels??? like for follow ones...:
<tr>
<td align="left">Strasse:</td>
<td>
<label for="name" class="control-label">
<p class="text-info">
<label style="color: #662819;" id="street"></label>
<i class="icon-star"></i>
</p>
</label>
<input type="text" class="edit-input" />
</td>
</tr>
and so on...
Upvotes: 0
Views: 336
Reputation: 1434
To make different labels editable at the same time, when you click a single link, you can use JQuery's each function, as shown in the following code:
$('a.edit').on('click',function(e){
e.preventDefault();
//Search for .control-label items
$('label.control-label').each(function(key,item){
var label = $(item);
label.hide();
label.siblings('input.edit-input').val(label.text()).show().focus();
});
});
Hope it helps!
Upvotes: 1