Split function in jQuery
Earlier I had posted about jQuery solution to replace string, substring, trim string and about all string functions, And In this post, see jQuery/JavaScript split function in action with example.
First declare a label and assign some text to it. We will split the text using space as delimiter.
<asp:Label ID="lblMessage" runat="server" Text="jQuery By Example Rocks!!" />
See below jQuery code, which makes use of split function and split the string with space.
<script type="text/javascript"> $(document).ready(function(){ var element = $("#lblMessage").text().split(" "); alert(element); }); </script>
Thing to note here is the variable "element" declared in jQuery code becomes an array and you can easily iterate through it. If you say alert(element[0]) then it will alert jQuery.
Mostly used and essential jQuery code snippets.
Mostly asked jQuery interview questions list.
Read my other helpful posts:
Disable-Enable all controls of page using jQuery
Enable/Disable all text boxes using jQuery
Feel free to contact me for any help related to jQuery. I will gladly help you.