Выбрать элемент не имеющий детей но имеющий текст
Как?
|
$("body *").each( function() { if($(this).children("*").length){return true;} else{ if($(this).text().length){ alert($(this).html()) }} }); |
Можно так еще вроде:
$('body *:not(:has(*)):not(:empty)') <!DOCTYPE HTML> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> <style> div {height: 20px;} div.with_text {background-color: red;} </style> <script> $(function() { $('body *:not(:has(*)):not(:empty)').addClass('with_text'); }); </script> </head> <body> <div></div> <div>aaaa</div> <div> <div></div> </div> <div>bbbb</div> <div></div> <div></div> <div>cccccc</div> </body> </html> |
walik,
Мну хотел c not - но он делает повторный проход по массиву - два not - два прохода... Хотя код красивше |
|
Часовой пояс GMT +3, время: 06:35. |