Saturday, 24 December 2016

Get Image Name from url using jquery


First add the jquery file by including following following line

Jquery library:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>



Html:

    <img width="75px" height="75px" border="0" alt="Top Tech" src="http://unitedassemblers.com/Artwork/Blank.jpg">



Jquery:

$(document).ready(function(){
    var name = $('img').attr('src');
    var fileNameIndex = name.lastIndexOf("/") + 1;
    var filename = name.substr(fileNameIndex);
    if(filename='Blank.jpg')
    {
     alert('image name is '+filename);
    }
})


Live Demo :

Click here for live demo

Wednesday, 7 December 2016

Smooth scroll using jquery

Smooth scroll using jquery


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<div class="">
    <a href="#commment" class="paythis">Go To comments</a>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div id="commment" style="height:300px;width:300px;background:#d7d7d7; text-align:center;">
    <h3>Comment Section</h3>
</div>



<script>
   $('a.paythis').on('click',function(event){
        event.preventDefault();
        var hash = this.hash;
         $('html, body').animate({
        scrollTop: $(hash).offset().top
      }, 5000, function(){
  
        // Add hash (#) to URL when done scrolling (default click behavior)
        window.location.hash = hash;
      });
    })
</script>

Monday, 13 June 2016

How to add class external to anchor that has href to other sites

Add class external to anchor that has href to other sites and target _blank to open them to new tab



jQuery

jQuery('a').filter(function() {
   return this.hostname && this.hostname !== location.hostname;
}).addClass("external");
jQuery('.external').attr('target','_blank');

Confirm before delete


Confirm before delete








Html:

<a href="delete.php"  onclick="return doconfirm()">Delete</a>

Javascript Function:


function doconfirm()
{
    contact=confirm("Are you sure you want to delete this?");
    if(contact!=true)
    {
        return false;
    }
}