How can I get elements in jQuery, starting from a specific template and ending with another template

<div id="Tab1"> <input type="text" id="ctl100_Tab1_one_text"/> <input type="text" id="ctl100_Tab1_two_text"/> </div> <div id="Tab2"> <input type="text" id="ctl100_Tab2_one_text"/> <input type="text" id="ctl100_Tab2_two_text"/> </div> 

I want all text fields in Tab1 to be split to Tab2

+4
source share
2 answers

Given the code entered:

 <div id="Tab1"> <input type="text" id="ctl100_Tab1_one_text"/> <input type="text" id="ctl100_Tab1_two_text"/> </div> <div id="Tab2"> <input type="text" id="ctl100_Tab2_one_text"/> <input type="text" id="ctl100_Tab2_two_text"/> </div> 

And the question is:

I want all text fields in Tab1 to be split to Tab2

 $('#tab1 input:text') 

However, given the name of your question:

How can I get elements in jQuery, starting from a specific template and ending with another template?

You can use:

 $('input:text[id^=startsWithPattern][id$=endsWithPattern]'); 

Using ^= (attribute-begins-with selector) and $= (attribute-end-with selectors) .

As shown with JS Fiddle demo .

+7
source

To get all input types in tab1, use this selector:

 $('#Tab1 input'); 
+1
source

Source: https://habr.com/ru/post/1333665/


All Articles