Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

jQuery substring function

Posted on 2014-12-08
2
171 Views
Last Modified: 2014-12-09
Hello Experts,

I have this short script below. For some reason only the line with the "substring" function creates and error. The error in the console is very long and looks as if there is a problem with the function. Can it be that i have to declare or convert the variable type before i use the "substring" function? As soon as i remove the "substring(4);" from line 3 in the code below there is no error.

$('.table tr').hover(function() {	
    var floorPlan = $(".td:eq(2)", this).text();		
    var floorImage = $("#viewimage > div").attr("id").substring(4);
    
    $("#viewimage > div img").css("visibility", "hidden");		
    $("#plan"+floorImage).find("img").css("visibility", "visible");

});

Open in new window

0
Comment
Question by:Refael
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40487855
$('.table tr').hover(function() {	
    var floorPlan = $(".td:eq(2)", this).text();		
    var floorImageStr = $("#viewimage > div").attr("id");
    floorImage = (floorImageStr || "").substring(4); // if the ID attribute is not set you get undefined and an error
    $("#viewimage > div img").css("visibility", "hidden");		
    $("#plan"+floorImage).find("img").css("visibility", "visible");

});

Open in new window

0
 

Author Closing Comment

by:Refael
ID: 40490025
leakim971, Thank you. Always!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question