Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

jQuery substring function

Posted on 2014-12-08
2
Medium Priority
?
203 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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.
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 …
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

636 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