Solved

jQuery substring function

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now