Campbell
Campbell

Reputation: 67

How do I insert a Div after a Class using Jquery or Javascript?

I don't have access to change the HTML. I'm either wanted to either:

     <div class="login-welcome">

                 <img src=" border="0" class="login-logo" alt="">

             <h2>Password recovery</h2> 
             <div class="info">
                 Please enter your username and we will send a password reset link to your email. If you can't remember what your username is please contact your administrator. If you don't have an email address registered with us you will need to contact your administrator to get your password reset. 
             </div>           
     </div>

     <div class="login-form">
         <form action="/account/forgot" method="post"><input name="__RequestVerificationToken" type="hidden" value="_1">

         <div class="login-field" tabindex="0"> 
             <label for="Username" style="display:none;">Username</label>
             <input class="form-control input-lg" id="Username" name="Username" placeholder="Username" required="true" type="text" value="">
         </div>
         <div class="login-button" tabindex="1">
             <input type="submit" class="btn btn-login btn-lg" id="continue" value=" Continue ">
         </div>

         <div class="login-forgot">
             or <a href="/account/login">Back to login</a>
         </div>
         </form>
     </div>
 </div>

I've tried the following code - but it didn't work.

  
$(document).ready(function(){
if(window.location.pathname == '/account/forgot'){
$( ".info" ).append( $( "<p>Test</p>" ) );
}
});
   

All help is appreciated!

Upvotes: 0

Views: 560

Answers (1)

Basir khan
Basir khan

Reputation: 168

there is an issue in your JavaScript code , for selecting class you need to add . with class in jquery like $('.myclass').hide() and for selecting id you need to add # with id like $('#myid').hide() and for selecting tag you need to do something that $("div").hide()... this is the basic concept of selecting specific tag , class or id in jQuery

$(document).ready(function(){
if(window.location.pathname == '/account/forgot'){
$( ".info" ).append("<p>Test</p>" );
}
});

the above code will only work on url /account/forgot so for testing you need to open that specific url

Upvotes: 1

Related Questions