I'm new to JQUERY and I want to change the button text when user clicks on it from "Reservar" to "RESERVADO" and from "RESERVADO" to "Reservar" again, and so on (toggle).
But I can only change the button text once, and then it doesn't change anymore. Any help is appreciated
$(document).ready(function() {
$("#rec").click(function() {
if ($("#rec").text() === 'RESERVADO') {
$("#rec").html("Reservar")
$("#rec").css('color', 'blue');
$("#6").appendTo($("#disponibles"));
} else if ($("#rec").text() === 'Reservar') {
$("#rec").html("RESERVADO")
$("#rec").css('color', 'red');
$("#6").appendTo($("#reservados"));
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="6" class="m-2 bg-white rounded-lg shadow-xl lg:flex lg:max-w-lg">
<img src="https://via.placeholder.com/50" class="w-1/1 lg:w-1/2 rounded-l-2xl">
<div class="p-6 bg-gray-50">
<h2 class="mb-2 text-2xl font-bold text-gray-900">Recursividad y contingencia</h2>
<p class="text-gray-600">Yuk Hui se aboca a esa tarea mediante una reconstrucción histórico-crítica del concepto de lo orgánico en filosofía, que aparece en la Crítica de la facultad de juzgar de Kant y plantea una ruptura respecto a la visión mecanicista del mundo para fundar
un nuevo umbral del pensamiento.</p>
<button id="rec" class="bg-transparent mt-5 hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded">
Reservar
</button>
</div>
</div>
The problem is the way you wrote your buttons tags there are spaces character before and after "Reservar" so just edit your button as following:
<button id="rec" class="bg-transparent mt-5 hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded">Reservar</button>
The structure of your button markup results in whitespace in its text value, which causes the comparison to fail. Trim that away and your script works.
Other tips:
Define constant values to reduce repeated selector processing.
Chain methods for simpler code.
Use a class or other abstract method to track state rather than text value. This is more robust as you can then change button text without breaking the script.
Button text really shouldn't be used for feedback. It's nonsensical to use a button, which implies that it's available for an action, to report what's already been done. Instead, consider removing the button and showing a simple message.
$(document).ready(function() {
const btnEl = $("#rec");
const sixEl = $("#6")
btnEl.click(function() {
const btnText = btnEl.text().trim(); // remove leading and trailing whitespace
if (btnText === 'RESERVADO') {
btnEl.text("Reservar").css('color', 'blue');
sixEl.appendTo($("#disponibles"));
} else if (btnText === 'Reservar') {
btnEl.text("RESERVADO").css('color', 'red');
sixEl.appendTo($("#reservados"));
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="6" class="m-2 bg-white rounded-lg shadow-xl lg:flex lg:max-w-lg">
<div class="p-6 bg-gray-50">
<button id="rec" class="bg-transparent mt-5 hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded">
Reservar
</button>
</div>
</div>
you can simly use a classList.toggle()
and some CSS ( with ::before )
$(document).ready(function()
{
$("#rec").click(function()
{
if (this.classList.toggle('RESERVADO') )
$("#6").appendTo($("#reservados"));
else
$("#6").appendTo($("#disponibles"));
});
});
#rec::before {
color : blue;
content : 'Reservar';
}
#rec.RESERVADO::before {
color : red;
content : 'RESERVADO';
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="6" class="m-2 bg-white rounded-lg shadow-xl lg:flex lg:max-w-lg">
<img src="https://via.placeholder.com/50" class="w-1/1 lg:w-1/2 rounded-l-2xl">
<div class="p-6 bg-gray-50">
<h2 class="mb-2 text-2xl font-bold text-gray-900">Recursividad y contingencia</h2>
<p class="text-gray-600">Yuk Hui se aboca a esa tarea mediante una reconstrucción histórico-crítica del concepto de lo orgánico en filosofía, que aparece en la Crítica de la facultad de juzgar de Kant y plantea una ruptura respecto a la visión mecanicista del mundo para fundar
un nuevo umbral del pensamiento.</p>
<button id="rec" class="bg-transparent mt-5 hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded"></button>
</div>
</div>
Related
I am trying to create a custom table as per the design and I am using Tailwind CSS for styling. I initially used table tags in HTML, but I was unable to style it properly, so I switched to using divs. However, I am facing an issue with the width size of the table head and row. The width is not consistent due to the content of the cells, can anyone please help me in resolving this issue?
Design:
What I get using div instead of table tags:
code:
<div className="flex flex-col">
<div className='flex text-sm font-bold text-gray-500'>
<div className='w-[170px] mr-2'>ລູກຄ້າ</div>
<div className='w-[140px] mr-2'>ປະກັນໄພ</div>
<div className='w-[120px] mr-2'>ບໍລິສັດ</div>
<div className='w-[90px]'>ວັນທີເລີ່ມຕົ້ນ</div>
<div className='w-[90px]'>ວັນທີສິ້ນສຸດ</div>
<div className='w-[90px]'>ສະຖານະ</div>
<div className='flex-1'>ຄ່າທຳນຽມ</div>
<div className='w-[170px]'></div>
</div>
</div>
<hr />
<div className='max-h-[700px] overflow-y-scroll shadow-sm insuranceReport rounded-b bg-white'>
{
orders?.map((order, index)=>(
<div key={index} className={`flex items-center px-5 ${index%2 == 0 ? 'bg-[#F5FCF5]' : 'bg-[#FFFFFF]'} py-4 text-sm hover:opacity-80`}>
<div className='w-[170px] flex items-center mr-2 font-sans text-sm'>
<div className="w-[2.3rem] h-[2.3rem] mr-2 rounded-full overflow-hidden aspect-square">
<img
src={
GetImageUrl(order?.profile, true)
}
alt={order?.name}
className="object-cover w-full h-full"
onError={({ currentTarget }) => {
currentTarget.onerror = null; // prevents looping
currentTarget.src= IMAGE_NOT_FOUND;
}}
/>
</div>
<div className='flex flex-col'>
<Link className='cursor-pointer hover:underline' to={`/sale/${order?.uuid}`}>
<span>{order?.customer?.name}</span>
</Link>
<span className='text-sm opacity-80'>{order?.customer?.gender}</span>
</div>
</div>
<div className='w-[140px] mr-2 text-sm'>{order?.product}</div>
<div className='w-[120px] mr-2 text-sm'>{order?.company}</div>
<div className='w-[90px] text-sm'>{FormatDate(order?.dateStart)}</div>
<div className='w-[90px] text-sm'>{FormatDate(order?.dateEnd)}</div>
<div className='w-[90px] text-sm'><span className={SaleStatusChecker(order?.status)?.color}>{SaleStatusChecker(order?.status)?.status}</span></div>
<div className='flex-1 text-sm'>₭ {order?.totalPrice?.toLocaleString()}</div>
<div className='flex items-start gap-3 text-sm'>
<button className='px-3 py-1 border-2 rounded-lg outline-none active:opacity-50 text-primary' onClick={()=>navigate(`/sale/${order?.uuid}`)}><FontAwesomeIcon icon={faEye}/> ລາຍລະອຽດ</button>
<button className='px-3 py-1 border-2 rounded-lg outline-none active:opacity-50 text-primary' onClick={()=>handleOpenOrderUpdateModal(order?.uuid)}><FontAwesomeIcon icon={faPenToSquare}/> ແກ້ໄຂ</button>
</div>
</div>
))
}
{
(orders?.length == 0 || orders == undefined || orders == []) && !isFetching ? <Empty/> : ""
}
{
isFetching &&
<LoadingData/>
}
</div>
</div>
I don't want to use flex and set a static width size of the div element. Is there any alternative solution to this issue?
Thank you in advance for your help!
I'm using the "Select" component from Radix-UI Radix Ui Select and the modal that pops up is overflowing the top of the screen, please see the attached image. overflowing modal. But when i have a few options, it works fine, please see attached imae => fine modal
The select button:
const SelectButton = (props: Props) => {
function handleOnValueChange(newValue:string){
props.onChange(newValue)
}
return (
<SelectPrimitive.Root defaultValue="blueberry" onValueChange={handleOnValueChange}>
<SelectPrimitive.Trigger asChild aria-label="Food">
{props.children}
</SelectPrimitive.Trigger>
<SelectPrimitive.Content className="rounded-lg mt-4 top-5">
<SelectPrimitive.ScrollUpButton className="flex items-center justify-center text-gray-700 dark:text-gray-300">
<ChevronUpIcon />
</SelectPrimitive.ScrollUpButton>
<SelectPrimitive.Viewport className="bg-white dark:bg-black p-2 rounded-lg shadow-lg top-5">
<SelectPrimitive.Group>
{props.options.map(
(f, i) => (
<SelectPrimitive.Item
//disabled={f === "Grapes"}
key={`${f}-${i}`}
value={props.toLower == undefined ? f.toLowerCase() : f}
className={cx(
"relative flex items-center px-8 py-2 rounded-md text-sm text-gray-700 dark:text-gray-300 font-medium focus:bg-gray-100 dark:focus:bg-gray-900",
"radix-disabled:opacity-50",
"focus:outline-none select-none"
)}
>
<SelectPrimitive.ItemText>{f}</SelectPrimitive.ItemText>
<SelectPrimitive.ItemIndicator className="absolute left-2 inline-flex items-center">
<CheckIcon />
</SelectPrimitive.ItemIndicator>
</SelectPrimitive.Item>
)
)}
</SelectPrimitive.Group>
</SelectPrimitive.Viewport>
<SelectPrimitive.ScrollDownButton className="flex items-center justify-center text-gray-700 dark:text-gray-300">
<ChevronDownIcon />
</SelectPrimitive.ScrollDownButton>
</SelectPrimitive.Content>
</SelectPrimitive.Root>
);
};
export default SelectButton;
I want to make a curved line between parts like here. Because if I now try to curve my borderline, the top also curves. I use nuxt.js and tailwind for css. I did not finish the code yet, but you can see where I want the lines. And I'm also checking how I will get the pictures in the right place.
Code
<template>
<div class="bg-gray-100 h-auto">
<div class="lg:mx-32 xl:mx-60 h-96 w-auto text-blue-900">
<div class="py-20">
<h3 class="text-4xl font-bold text-center">Nuestro proceso de Check-in</h3>
</div>
<h1 class="font-bold text-7xl text-gray-300 ml-10">1</h1>
<div class="relative border-l-2 border-b-2 border-dashed rounded-xxl border-blue-900 w-1/2">
<div class="m-10">
<h3 class="text-3xl font-bold items-end col-start-1 row-start-2 h-auto"><u>Escanea</u> el
documento<br>del viajero</h3>
<p class="col-start-1 row-start-3">
Con solo escanear el código MRZ ubicado en la parte inferior
del DNI o Pasaporte del viajero, nuestra app registra al
instante todos sus datos personales.
</p>
</div>
</div>
<div class="relative w-1/2">
<!-- <div class="layer0 bg-contain bg-no-repeat h-full w-2/3" :style="passport"></div>
<div class="layer1 bg-contain bg-no-repeat h-full w-2/3" :style="phone"></div> -->
</div>
<div class="relative grid grid-cols-2 grid-rows-5 h-96 w-auto">
<div class="absolute border-r-2 border-dashed rounded-xxl border-blue-900 bg-contain bg-no-repeat h-full w-1/2 row-span-4"
:style="sign"></div>
<div class="col-start-2 ml-5">
<h1 class="font-bold text-7xl text-gray-300 col-start-2 row-start-1">2</h1>
<h3 class="text-3xl font-bold items-end col-start-2 row-start-2 h-auto"><u>Firma</u> del huésped
</h3>
<p class="col-start-2 row-start-3">
Una vez escaneado su documento, completa el registro
con la firma digital de tu huésped, usando su
dedo o un puntero
</p>
</div>
</div>
</div>
</div>
</template>
<style>
.layer0 {
position: relative;
top: 0;
left: 0;
z-index: 0;
}
.layer1 {
position: absolute;
top: 0;
left: 62%;
z-index: 1;
}
</style>
<script>
export default {
components: {},
data() {
return {
passport: {backgroundImage: "url(passport.png)"},
phone: {backgroundImage: "url(phone_scan.png)"},
sign: {backgroundImage: "url(sign.png)"}
};
}
}
</script>
You can go to figma.com
use the pen tool
create the shape/lines you want.
then right click the shape/lines Copy as SVG
paste it in your code.
As it is as SVG code you can apply CSS to it and use it how ever you want
i have two buttons, blue and red.
i want to set when red button is clicked/focused blue button should also turn red.
how can i achieve it using tailwind css.
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet"/>
<button class="focus:bg-red-700 bg-red-400 font-bold px-4 py-4 rounded-lg">
RED
</button>
<button class=" bg-blue-400 font-bold px-4 py-4 rounded-lg">
BLUE
</button>
Tailwind don't has the css combinators. Guess, you have two way to achieve this.
Create an extra css file and add this line
button.bg-red-400:focus ~ button.bg-blue-400 {
background-color: rgba(185, 28, 28, 1);
}
button.bg-red-400:focus~button.bg-blue-400 {
background-color: rgba(185, 28, 28, 1);
}
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet" />
<button class="focus:bg-red-700 bg-red-400 font-bold px-4 py-4 rounded-lg">RED</button>
<button class="bg-blue-400 font-bold px-4 py-4 rounded-lg">BLUE</button>
You can create your own custom class with #Variants documentation, but not with a link from CDN.
Before using the CDN build, please note that many of the features that make Tailwind CSS great are not available without incorporating Tailwind into your build process. documentation
Solution with javascript
// Select all elements with `bg-blue-400` class
const blueBox = document.querySelectorAll('.bg-blue-400');
const changeColor = ev => {
// Define button in the DOM
const button = ev.target.closest('button');
// Check, if the button was clicked
if (button) {
// Chenge color in the DIVs
for (const box of blueBox) {
box.classList.add('bg-red-400');
box.classList.remove('bg-blue-400');
}
return;
}
// If clicked outside, the color will switch back
for (const box of blueBox) {
box.classList.add('bg-blue-400');
box.classList.remove('bg-red-400');
}
};
document.addEventListener('click', changeColor);
<link href="https://unpkg.com/tailwindcss#^2/dist/tailwind.min.css" rel="stylesheet" />
<div>
<button class="one bg-red-400 font-bold px-4 py-4 rounded-lg">RED</button>
<div class="bg-blue-400 font-bold px-4 py-4 rounded-lg">BLUE</div>
</div>
<div class="two bg-blue-400 font-bold px-4 py-4 rounded-lg">APPLY COLOR HERE</div>
How to adjust the css in a trix-editor so that I can change its style wherein it would stop resizing after pressing enter few times.
<div class="bg-white flex flex-wrap self-end items-center w-full text-xl">
<!-- <input type="text" class="flex-auto appearance-none text-base p-2" placeholder="Write a message..."> -->
<VueTrix class="flex-auto appearance-none text-base p-2" #keypress.enter="sendMessage" v-model="editorContent" plloreaceholder="Press shift + enter to send your message" localStoragem ipsum/>
</div>
This is the a url to the video attachment :
https://cdn.discordapp.com/attachments/496820557627654174/646552238126399489/Blacktrail_-_Chat_Feature_-_Google_Chrome_2019-11-20_11-23-51.mp4
My suggestion would be: Configure in the tailwind.config.js a custom maxHeight
// tailwind.config.js
module.exports = {
theme: {
maxHeight: {
'four-lines': '96px'
}
}
}
The class will be: .max-h-four-lines