Solved

jquery slideToggle question

Posted on 2014-02-28
1
242 Views
Last Modified: 2014-02-28
When someone clicks on the text "Click here to view phone number" the phone number appears below the text and it pushes content down. What I would like to do is the phone number should appear where the text is so the text will be hidden once the link was clicked (phone number replaces text).

				<div id="showphone">Click here to view phone number</div>
<div class="phone" style="display: none;"><span itemprop="telephone"><?php echo $attorneysStuff['bizPhone'];?></span></div>

<script>
   $(document).ready(function() {
        $('#showphone').click(function() {
                $('.phone').slideToggle("slow");
        });
    });

	</script>

Open in new window

0
Comment
Question by:seopti
1 Comment
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39896663
In that case I would suggest you change your html to this

<div id="showphone" data-tel="<?php echo $attorneysStuff['bizPhone'];?>">Click here to view phone number</div>

Open in new window


And your jquery would be
   $(document).ready(function() {
        $('#showphone').click(function() {
                $('#showphone').html($(this).data("tel"));
        });
    });

Open in new window


There is no point in the extraneous HTML if you are not using it.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)

759 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

21 Experts available now in Live!

Get 1:1 Help Now