1

I'm using accordion jQuery UI , in each accordion there are some fields, I want to be able to change each accordion Title by using the first input[type=text] of each accordion

This JS which I wrote, but only work for the first input[type=text] of the first accordion and I want for each accordion

$('.redux-groups-accordion-group input[type=text]:first').live('keyup',function(event) {
     $(this).parents('.redux-groups-accordion-group:first').find('.redux-groups-header').text(event.target.value);
});

HTML :

<div id="redux-groups-accordion">
    <div class="redux-groups-accordion-group">
        <h3 class="ui-accordion-header">
            <span class="redux-groups-header">New Slide Title</span>
        </h3>
        <div class="ui-accordion-content">
            <input type="hidden" name="id" />
            <input type="text" name="title" />
            <input type="text" name="tags" />
        </div>
    </div>
    <div class="redux-groups-accordion-group">
        <h3 class="ui-accordion-header">
            <span class="redux-groups-header">New Slide Title</span>
        </h3>
        <div class="ui-accordion-content">
            <input type="hidden" name="id" />
            <input type="text" name="title" />
            <input type="text" name="tags" />
        </div>
    </div>
</div>
Abdullah Almesbahi
  • 271
  • 1
  • 2
  • 10

2 Answers2

0

Demo http://jsfiddle.net/v7XgA/

by the way live is deprecated:

I have use .on instead of live also you were using :first in your Jq code hence it was aiming for all get rid of :first

Rest should fit the need :)

Try this

$('.redux-groups-accordion-group input[type=text]').on('keyup',function(event) {
     $(this).parents('.redux-groups-accordion-group:first').find('.redux-groups-header').text(event.target.value);
});
Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
0

Try

$('#redux-groups-accordion').on('keyup', '.redux-groups-accordion-group input[name="title"]', function (event) {
    $(this).closest('.redux-groups-accordion-group').find('.redux-groups-header').text(this.value);
});

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531