Skip to main content

Posts

Showing posts with the label JavaScript

Split a string and get last match in jQuery and Javascript

Method 1: str = "~test content ~thanks ok ~eabhyas.blogspot.com";    strFine =str.substring(str.lastIndexOf('~')); console.log(strFine ); Output: ~eabhyas.blogspot.com Method 2: str = "~test content ~thanks ok ~eabhyas.blogspot.com";    console.log(str.split('~').pop()); OR str = "~test content ~thanks ok ~eabhyas.blogspot.com";  var parts = str.split("~"); var what_you_want = parts.pop(); Output: eabhyas.blogspot.com Method 3: str = "~test content ~thanks ok ~eabhyas.blogspot.com";    arr = str.split('~'); strFile = arr[arr.length-1]; console.log(strFile ); Output: eabhyas.blogspot.com

Split Text into Lines - SplitLines | Free jQuery Plugins

SplitLines is a lightweight jQuery plugin which allow you to split  block of text into  multiple lines using specific html tag(s) and defined width & line height .  SplitLines ( $.splitLines() ) is a jQuery plugin that splits new lines of wrapped text into their own HTML elements, allowing you to animate or operate on each line individually. Works with nested HTML tags as well. splitLines() takes a block of text and splits it up into separate lines based on the width of the box or a width passed to the function. Requirements jQuery 1.4.2 or later How to Split Text By Lines Include required libraries on page. <script src="//code.jquery.com/jquery.min.js"></script> <script src="jquery.splitlines.js"></script> HTML: Below is the sample text which need to split into lines. <div id="mycontent">     This is an <strong>example</strong> of some long text     that we want to split into lines. </div>   Jav

Highlight the navigation menu for the current page

JavaScript: <script src="JavaScript/jquery-1.10.2.js" type="text/javascript"></script> <script type="text/javascript">     $(function() {         // this will get the full URL at the address bar         var url = window.location.href;         // passes on every "a" tag         $(".topmenu a").each(function() {             // checks if its the same on the address bar             if (url == (this.href)) {                 $(this).closest("li").addClass("active");                 //for making parent of submenu active                $(this).closest("li").parent().parent().addClass("active");             }         });     });        </script> HTML Code: <div class="topmenu">   <ul class="nav">     <li><a href="index.html">Home</a></li>     <li><a href="about.html">About Us</a></li>