1

I have three elements, which are sliding on the screen, i want to get the text of element which is currently showing on the screen, I tried .text() function, but this returns the text of all the s elements, is there any way using javascript or jquery to do this.

<div id="text"> <span style=" font-size:100px;text-align:center;">koko</span> <span style=" font-size:100px;text-align:center;">abc</span> <span style=" font-size:100px;text-align:center;">efh</span> </div> $(document).ready(function(){ $('#text').mouseover(function(){ var txt = $('#text span').text(); alert(txt); }); }); 
5
  • 1
    Please try google or jQuery website first Commented May 20, 2012 at 9:13
  • no homeworking...only researching + some helping here....common! can't you just google it up or look at the jquery docs? And I might've helped you if you were knew to programming in js...but you don't seem to be... Commented May 20, 2012 at 9:16
  • if u read my question's description, i clearly mentioned this thing, i tried .text() function, but its not working, & its not a home work. Commented May 20, 2012 at 9:18
  • What library are you using to make the slides change? Does it fire an event when slide changes? Commented May 20, 2012 at 9:32
  • cycle for slide showing, & touchwipe to listen to events Commented May 20, 2012 at 9:55

2 Answers 2

6

demo or another here

code

$('#text > span').mouseover(function(){ var txt = $(this).text(); alert(txt); }); 
Sign up to request clarification or add additional context in comments.

3 Comments

is there a way, to save this text not only on mouseover but as my slide change?
you will have to set an event listener to listen for slide changes and set a callback to be called when slide changes. It will depend on what library you are using for changing the slides. Some of them allow you to set callbacks. That will also inform you which slide is the current slide and you can accordingly pick the text from it.
@tapan i am using "cycle" & "touchwipe"
0

Since you are using the cycle plugin, the active slide is given the class "activeSlide". You can get the text of the active slide by doing something like $('.activeSlide').text(); You can also set a callback in the options while initialising the cycle plugin. You can look at the options that you can set with cycle here: http://jquery.malsup.com/cycle/options.html

You will be able to use the "after" event callback in case you want to do something everytime the slide changes.

$(document).ready(function () { $('#text').cycle({ after: function (currSlideElement, nextSlideElement, options, forwardFlag) { alert($(nextSlideElement).text()); } }); }); 

6 Comments

can you please give the example of using after function, i am unable to understand it from documentation.
you may have to do $(currSlideElement).text(); please try both and let me know what works.
nothing happens, now slides are also not scrolling, after adding "after" to cycle's setting
thats weird! Can you try doing this and see if it works ? $.fn.cycle.defaults.after = function (currSlideElement, nextSlideElement, options, forwardFlag) { alert(currSlideElement.text()); }
Oh, there was a syntax error in what i had written. I had forgotten to close the curly brace for the function :D. Try now.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.