I have this scenario.
In title <h2></h2> I want to put fontawesome icon before text.
Ex.     
  <h2 id="test"><i class="fa fa-cog"></i> THIS IS TITLE</h2>
I will add manual icon for all title, but if any title stay empty (without icon), the script add default icon
  <i class="fa fa-angle-double-left"></i>
I have tried with this script but it is not working.
$("#test(:empty)").append('<h2><i class="fa fa-angle-double-left"></i></h2>');
Any suggestion to fix this problem?
Edit This one i need for all blocks in sidebar. Structure of block's is:
        <div class="sidebar">
        <h2><i class="fa fa-users"></i><a href="#"> Title 1</a></h2>
        <ul>
                        <li>
                            <div class="user"></div>
                        </li>
        </ul>
    </div>
And 2-nt sidebar same class different title
        <div class="sidebar">
        <h2><i class="fa fa-users"></i><a href="#"> Title 2</a></h2>
        <ul>
                        <li>
                            <div class="user"></div>
                        </li>
        </ul>
    </div>
And block 3-th is without icon
        <div class="sidebar">
        <h2>HERE ADDD DEFAULT ICON <a href="#"> Title 1</a></h2>
        <ul>
                        <li>
                            <div class="user"></div>
                        </li>
        </ul>
    </div>    
I hope now is clear
                        
You can do it with CSS using Pseudo-Classes.
JSFiddle