es131245 Posted October 27, 2012 Share Posted October 27, 2012 (edited) <ul><li>1 <ul> <li>11</li> <li>12</li> <li>13</li> </ul></li><li>2 <ul> <li>21 <ul> <li>212</li> </ul> </li> <li>22</li> </ul></li><li>3</li></ul> $(ul li).each(function(){$(this).html('_'+$(this).html());}); works only for first levelmoreover $(ul li,ul li ul li,ul li ul li ul li).each({$(this).html('_'+$(this).html());}); isnt working ether What is wrong?Why selectors work diferent way than css? PS $(ul li).each(function(){$(this).css({'background':'url("favicon.ico") top left no-repeat'});}); Works ( blame html\(\)?) Edited October 27, 2012 by es131245 Link to comment Share on other sites More sharing options...
Ingolme Posted October 28, 2012 Share Posted October 28, 2012 You should be passing a string to the $() function.$("ul li") Link to comment Share on other sites More sharing options...
es131245 Posted October 29, 2012 Author Share Posted October 29, 2012 sorry error while typing topic. Topic isnt solved yet. <html><head><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script></head><body><ul><li>1 <ul> <li>11</li> <li>12</li> <li>13</li> </ul></li><li>2 <ul> <li>21 <ul> <li>212</li> </ul> </li> <li>22</li> </ul></li><li>3</li></ul><script type="text/javascript">$(document).ready(function(){$('ul li').each(function(){$(this).html('_'+$(this).html());});});</script></body></html> Link to comment Share on other sites More sharing options...
justsomeguy Posted October 29, 2012 Share Posted October 29, 2012 You keep setting the HTML, so you're probably overwriting the HTML you've already changed with something else. If applying CSS styles works, and setting HTML doesn't, then that sounds like a possibility. Link to comment Share on other sites More sharing options...
dsonesuk Posted October 30, 2012 Share Posted October 30, 2012 (edited) The problem is, you are not just targeting <li>11</li> but you will be targeting all the sub level list items as well, within <li> 1 <ul> <li>11</li> <li>12</li> <li>13</li> </ul></li> and end up overwriting them each time, the only sure thing to target is the <li> tag itself, and replace with '<li>_'. $('ul').html($('ul').html().replace(/<li>/gi,'<li>_')); As usual had to add amendment to cover crappy IE, as in i for case insensitive Edited October 30, 2012 by dsonesuk Link to comment Share on other sites More sharing options...
es131245 Posted October 30, 2012 Author Share Posted October 30, 2012 (edited) replace doent help because i use $(this).attr('id') Prepend helped $('ul#index li').each(function(){if(typeof($(this).attr('id'))!='undefined') {$(this).prepend('<span class="number">'+$(this).attr('id').substr(4)+'</span>');} SOLVED thank you Edited October 30, 2012 by es131245 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now