javascript - Hide id dynamically by jquery -


i have 3 three divs

<div id= "product_1"></div> <div id= "product_2"></div> <div id= "product_3"></div> <div id= "product_4"></div> <div id= "product_5"></div> 

i changing ids dynamically

var hotelcode = "cunmxhidd,cunmxmaya,cunmxdsan" var splittedhotelcode = hotelcode.tostring().split(','); jquery.each(splittedhotelcode, function(i, hotelcode) {  $("#product_"+ i).attr("id","product_"+ hotelcode); }); 

after want hide divs not been indexed product_4 , product_5

now dom

<div id= "product_cunmxhidd"></div> <div id= "product_cunmxmaya"></div> <div id= "product_cunmxdsan"></div> <div id= "product_4"></div> <div id= "product_5"></div> 

i dont want hard code. possible can hide them jquery ?

you use length of array , slice method.

$('div[id^=product]').slice(splittedhotelcode.length).hide(); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -