Solved

jQuery substring function

Posted on 2014-12-08
2
172 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
[X]
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
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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)

730 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