Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
If I defined some div in a code like this:
if(...)
{
// code
// code again
if(...)
{
// code
<div> first div </div>
//code code
}
}
<div> second div </div>
So "first div" always appears before the "second div", how can I switch the order of div's displaying? Thanks.
how about this (you need div id's)
$('#secondDiv').insertBefore('#firstDiv').remove();
Change your code to:
if(...)
{
// code
// code again
if(...)
{
// code
<div id='firstDiv'> first div </div>
//code code
}
}
<div id='secondDiv'> second div </div>
You can show the second <div> in a predetermined place by appending it to another div. For example:
HTML:
<div id="fake-second"></div>
<div id="first"> first div </div>
<div id="second"> second div </div>
jQuery:
$("#fake-second").append($("#second").html());
$("#second").hide();
JS Fiddle Demo
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
My code is :
<?php
$msgArray = [
0=>'HTTP means HyperText Transfer Protocol.',
1=>'HTTPS,Hyper Text Transfer Protocol Secure is the secure version of HTTP.'
];
foreach ($msgArray as $key => $msg) :
$small = substr($msg, 0, 5);?>
<span class="lessText"><?= $small ?></span>
<span class="fullText" style="display: none"><?= $msg ?></span>
<sub class="viewMore" style="color:#3399ff;padding-left2%;cursor: pointer;">view more >></sub>
<sub class="viewLess" style="color:#3399ff;padding-left2%;cursor: pointer;display: none"><< view less</sub>
<?php endforeach; ?>
<script type="text/javascript">
$(".viewMore").click(function(){
$(".viewMore").hide();
$(".lessText").hide();
$(".fullText").show();
$(".viewLess").show();
});
$(".viewLess").click(function(){
$(".viewLess").hide();
$(".fullText").hide();
$(".lessText").show();
$(".viewMore").show();
});
</script>
Here, I am trying to display a long string to its 1st five character and after clicking view more it will be displayed the whole string.
this is working fine if there is only one. Inside the forEach loop its not working properly. Please solve this problem.
Wrap the HTML fragment in a container.
<div class="container">
<span class="lessText"><?= $small ?></span>
<span class="fullText" style="display: none"><?= $msg ?></span>
<sub class="viewMore" style="color:#3399ff;padding-left2%;cursor: pointer;">view more >></sub>
<sub class="viewLess" style="color:#3399ff;padding-left2%;cursor: pointer;display: none"><< view less</sub>
</div>
Then modify your script to use DOM traversal method to target the desired element. Using .closest() traverse up to common parent i.e. container then using it as context or use .find()
$(".viewMore").click(function () {
var container = $(this).closest('.container')
$(".viewMore, .lessText", container).hide(); //container.find('.viewMore, .lessText').hide()
$(".fullText, .viewLess", container).show();
});
$(".viewLess").click(function () {
var container = $(this).closest('.container')
$(".viewLess, .fullText", container).hide();
$(".lessText, .viewMore", container).show();
});
Write it in this structure:
<?php foreach(): ?>
<div class="holder">
<div class="lessText"></div>
<div class="fullText"></div>
<div class="viewMore"></div>
<div class="viewLess"></div>
</div>
<?php endforeach; ?>
JS:
$('.holder .viewMore').click(function(){
$(this).closest('.holder').find('.lessText').hide();
$(this).closest('.holder').find('.fullText').Show();
});
$('.holder .viewLess').click(function(){
$(this).closest('.holder').find('.lessText').Show();
$(this).closest('.holder').find('.fullText').hide();
});
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have following data in mysql, and I want to echo in this format:
Data:
Name,Image URL,Link
I want to print it dynamically like this : http://screensaver.cf/screensavers.php
I don't know user's screen width, still I want it to appear as much as possible in width.
How can I do this in html and PHP?
My code:
<?php
require("config.php");
?>
<div id="main-wrap">
<div class="container">
<div id="main">
<div id="content"><div id='wsite-content' class='wsite-elements wsite-not-footer'>
<div class="paragraph" style="text-align:left;">
<?php
$sql='SELECT * FROM `games` where 1=1';
$data = mysql_query($sql);
echo '<h4 class="result">Result:</h4>';
while($row = mysql_fetch_row($data)){
$table=WHAT TO DO HERE TO MAKE IT LOOK LIKE THAT???????
echo $table;
echo '<br><br>';
}
?>
</div>
</div>
</div>
</div>
</div>
<?php
include("footer.php");
?>
P.S I know mysql is depreciated and I am constantly working to learn Mysqli, as I am in 8th class, I don't have much time.
<style>.a{float:left;}
</style>
>
in while loop use this
<div class = "a">
<?php <img src='".$row['url']."' width='140' height='140'> ?>
</div>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am a newbie in coding etc. so I am trying to get some help from you guys. I have to put every single file (.php) in one .html/php file.
Now I got this code:
<html>
<head>
<style type='text/css'>
span {
text-decoration:underline;
color:blue;
cursor:pointer;
}
</style>
<script>
// show the given page, hide the rest
function show(elementID) {
// try to find the requested page and alert if it's not found
var ele = document.getElementById(elementID);
if (!ele) {
alert("no such element");
return;
}
// get all pages, loop through them and hide them
var pages = document.getElementsByClassName('page');
for(var i = 0; i < pages.length; i++) {
pages[i].style.display = 'none';
}
// then show the requested page
ele.style.display = 'block';
}
</script>
</head>
<body>
<p>
Show page
<span onClick="show('Page1');">1</span>,
<span onClick="show('Page2');">2</span>,
<span onClick="show('Page3');">3</span>.
</p>
<div id="Page1" class="page" style="">
Content of page 1
</div>
<div id="Page2" class="page" style="display:none">
Content of page 2
</div>
<div id="Page3" class="page" style="display:none">
Content of page 3
</div>
</body>
So my question is; how do i put my files into the 'Content of page 1/2/3'?
Thanks in advance!
Try include("[path to your file]"); or include_once("[path to your file]");
http://php.net/manual/en/function.include.php
http://php.net/manual/en/function.include-once.php
If you need to combine other PHP files with this HTML file, simply change the name of this file to .php if it isn't already. Then copy/paste your code (in order each file is processed) into the top of this file. Be sure to surround your php with <?php and ?>. The HTML will still display correctly if it's inside a PHP file.
Note: This is not good practice, but it will accomplish what your teacher is requesting.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need the data to have a different style if the sold = 0 in the mysql table
and when i use the code below the website shows a blank white page
(?=$vehicle-> this is the vehicle reference
and sold is the column withing the sql table
<?php
if (?=$vehicle->sold?!= 1)
{
<div class="foo">
<div class="fboverlay"></div>
<a>
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
</a>
</div>
}
else {
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
}
?>
You need to learn the PHP from the basics. Learn about operators, PHP and HTML secion, etc..
Anyway, i fixed your code. The condition is if $vehicle->sold is not equal to 1. But i think, (in your OP you mentioned it should be 0) you want this: $vehicle->sold == 0
//Use sytnax like this. See php opeartors.
if ($vehicle->sold != 1) {
?> <!-- Close the php -->
<div class = "foo">
<div class = "fboverlay"></div>
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
</div>
<?php
//Open the php again
} else {
?> <!-- close the php -->
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
<?php //Open again
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is a code snippet I have and I would like to be able to select the out of PHP. When I try to grab the PHP output and store it into a variable, I receive "undefined".
<h1 id=<?php echo '$test; ?> class="list-name--original">
My last attempt I tried this code:$("h1.list-name--original")[0].outerHTML);
Why not just put all your PHP output in a variable
<script>
var data = '<?=$test?>';
</script>
You can then set the contents of an H1 tag like this
<h1 id="myid"></h1>
<script>
$('h1#myid').text(data);
</script>
Try
<h1 id="<?php echo $test; ?>" class="list-name--original">
in jQuery
$(".list-name--original").html();
or
$("#<?= $test ?>").html();
Try this:
<?php $test = "Hello world!"; ?>
<h1 id="example" class="list-name--original"><?php echo $test; ?></h1>
<script language="javascript">
$("#example").html();
</script>