Note that there are some explanatory texts on larger screens.

plurals
  1. POIdentify accordion-selector and tab using jQuery DOM based methods?
    primarykey
    data
    text
    <p>I have this function where I send in the id of the jquery-ui-accordion,and jquery-ui-tab. The function changes both it's error state. </p> <p>I want to make this function identify both selector and tab automatically, so that I don't need to send it any parameters. </p> <pre><code>function show_error(selector,tab) { var $this = $(selector); // parent tab var parent = $("#accordion").parent(); //parent.adderror(); // the content $this.adderror(); // the header var header = $this.attr("aria-labelledby"); $("#"+header).adderror(); // the tab //This didn't work -var tab = parent.attr("aria-labelledby"); $("#"+tab).parent().adderror(); } </code></pre> <p>To use this function call as</p> <pre><code>&lt;div id="tabs-1"&gt; &lt;div id="accordion_oms"&gt; &lt;div&gt; &lt;script&gt;show_error("#ui-accordion-accordion_oms-panel-0","ui-id-1")&lt;/script&gt; &lt;/div&gt; &lt;div&gt; &lt;script&gt;show_error("#ui-accordion-accordion_oms-panel-1","ui-id-1")&lt;/script&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="tabs-2"&gt; &lt;div id="accordion_fulfillment"&gt; &lt;div&gt; No error here &lt;/div&gt; &lt;div&gt; &lt;script&gt;show_error("#ui-accordion-accordion_fulfillment-panel-1","ui-id-1")&lt;/script&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>The problem is I use this in loads of places my rails application, and if something is changed/moved, I need to change them accordingly. Is there any way to make the function as just show_error(), and then it picks up the tab and selector automatically? I will be calling the function in the right place. So for eg-: show_error() , and it automatically identifies which accordion and tab it was for dependent on the place from where it was called.</p> <p>If you wanna experiment, here is a JSFiddle - <a href="http://jsfiddle.net/bxeP7/5/" rel="nofollow">http://jsfiddle.net/bxeP7/5/</a></p> <p>It's something like</p> <pre><code>&lt;h3&gt;Orders&lt;/h3&gt; &lt;div&gt; &lt;% if @order_error.present? %&gt; &lt;%= @order_error.html_safe %&gt; &lt;%= javascript_tag("$(function() {show_error('#ui-accordion-accordion_oms-panel-0','ui-id-1');});") %&gt; &lt;% else %&gt; &lt;%= render "trace/display_tabular_data", :data =&gt; @order %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;h3&gt; Order Items &lt;/h3&gt; &lt;div&gt; ... &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload