Solved

jQuery substring function

Posted on 2014-12-08
2
167 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to check and insure value only has 5  numbers (0-9)? 2 20
Scroll 5 news at a time. 4 28
JavaScript let vs var 5 27
If condition on Html with Asp 11 18
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

822 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