보다 효율적인 방법으로 자파렌트 () 에서 jquery 자파렌트 () 등 상위 ()

이 스크립트입니다 자파렌트 () 를 사용하여, 내가 내 자신을 찾을 먹어서나 I& # 39 m, 최대 7 회 연속 afaq 요소. 한편, 이 작품을 쉽게 할 수 있다고 해야 할 것 같다 / this/ 함수은 I& # 39 m, 못했다. 다른 어떤 것보다 더 많은 아이디어를 구체적인 클래스뿐만 / ids 요소이면?

기본적으로 div id '외부' 로 요약할 수 있을 때 나는 내 질문에 다운되어도 액세스하면 스팬할 innerSpan& # 39, & # 39 대한 참조입니다 (id; html 에서 (아래 참조).

<div id='outer'>
    <a href="some_url">
        <span id="inner">bla bla</span>
    </a>
</div>

따라서 현재, 꼭 이래야겠어요 뭔가 다음과 같습니다.

'var = $ (& # 39, # inner& # 39;) 외부 자파렌트 () 자파렌트 ()'

그리고 그 미친 네스트된 요소를 통해 얻을 수 있다.

  • 다른 example:*

여기 내 html:

<div id="options_right">
            <table id="product_options_list" class="table table-bordered">

            <tbody id="1">
                <tr>
                    <td>
                        <select name="option_1_val[0]" class="option_table_select">
                            <option value="Red">Red</option>
                            <option value="Blue">Blue</option>
                            <option value="Green">Green</option>
                            </select>
                    </td>
                    <td>
                        <table class="table sub_options" id="0">
                            <tbody>
                            <tr>
                                <td>
                                    <select name="option_1_sub[0][]" class="option_table_select  sub_option_select">
                                        <option value="">None</option>
                                        <option value="2">Size</option>
                                    </select>
                                    <div class="sub_option_value_holder">
                                        <select name="option_1_sub_val[0][]" class="sub_option_values" style="display:none;"></select>
                                    </div>
                                </td>
                                <td>
                                    <a href="#" class="remove_sub_option btn btn-primary">Remove</a>
                                </td>
                                <td>
                                    <a href="#" class="add_sub_option btn btn-primary">Add Another</a>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </td>

그리고 내 스크립트입니다. 내가 쓴 《 id 를 주 행뿐만 기능과 전달해야 하는 것이 아니라 동적으로 추가할 수 있는 보조 테이블 id 그래서 표 본문 행. # 39 이 질문에 대한 기능을 하지만 기본적으로 필요한 don& 있습니다 t really, 침입탐지시스템 (ids) 같은 느낌이 있습니다.

get_suboption_row($(this).parent().parent().parent().parent().parent().parent().parent().attr('id'), $(this).parent().parent().parent().parent().attr('id'));

감사합니다

이스피들: http://jsfiddle.net/Hg4rf/

다른 이벤트 트리거하거나 추가 (add)

질문에 대한 의견 (1)
해결책

2 네스트된 테이블뿐 합니다. 이 두 가지 방법을 사용할 수 있습니다 'afaq 그리웠댔지 DOM 레벨 ()' 또는 '자파렌츠 오클로스트 ()'

&gt. - '오클로스트 ()' 여행을 위해 제공된 선택기를 DOM 진단트리는 클린업합니다 발견할 때까지 a 매치

  • '자파렌츠 ()' 에 대한 추가 # 39 위로 이동하는 DOM 진단트리는 document& 임시 루트 요소를 컬렉션, 각 요소를 가리킨다. 그런 다음 필터링합니다 취합은 선택기를 기반으로 하는 경우 공급

Flexlm*용 네스트된 표:

$(this).closest('table').closest('tbody').attr('id');

<!

$(this).parents('table').parents('tbody').attr('id');
  • [이스피들 데모] [3] *
해설 (7)

생쥐라. '오클로스트 ()' # 39 는 어떤 you& 찾고, re:)

해설 (0)

Css 클래스 이름을 알고 있는 경우 해당 요소의 '' 가장 '' () 메서드를 호출할 수 있습니다.

var thatParent=  $("#someId").closest(".somCSSClassName")

그래서 다시 쓰일 코드에 따라 cal

get_suboption_row($(this).closest("someClass").attr('id'),
                $(this).closest("someOtherClass").attr('id'));

편집: 이후 이스피들 보기

상위 클래스 이름을 사용하여 내려받습니다 표.

 alert($(this).closest('tbody').closest('.table-bordered').attr('id'));

Apc® 예제: http://jsfiddle.net/Hg4rf/2/

해설 (7)