PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 8, 2022

[FIXED] How to apply the css on all ID starting with

 September 08, 2022     ajax, css, html, javascript     No comments   

Issue

On my website I have an AJAX search form. The HTML code displays this ID:

id="edit-field-geolocation-proximity-center-geocoder--Bq5Bx8zXA1A"

I want to apply a style to it. My problem is that the code at the end of Bq5Bx8zXA1A changes with each search.

How to style all ID starting with :

id="edit-field-geolocation-proximity-center-geocoder--"

UPDATE

Here is my current CSS code, it works on non-AJAX forms. But for those who have AJAX enabled, it doesn't work because there is a random code added to the background of the ID :

#edit-field-geolocation-proximity-center-geocoder .form-item {
    margin-top: 0rem;
}

enter image description here


Solution

Welcome to Stack Overflow! I can help with that. One way to achieve what you are looking for in pure CSS is with an attribute prefix selector (which uses a form of regular expressions). In your case the following would likely do the trick:

[id^="edit-field-geolocation-proximity-center-geocoder"] .form-item {
  /* your styles here :) */
}

This thread offers a lot of additional excellent methods on how to use regex in CSS if you would like to do some additional reading.



Answered By - Aaron Meese
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing